Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ There is a lot of information in a tiny package. When things go wrong in your ap
Visit this url: [localhost:3000/users](http://localhost:3000/users) and then find the log entry. Then open up the readme.md you copied onto your local machine and fill out this information:


HTTP verb used in this request:
URL:
Controller Name:
Controller Action:
View File Name:
Layout File Name:
Response code of the request:
HTTP verb used in this request: get
URL: http://localhost:3000/users
Controller Name: Products
Controller Action: index
View File Name: localhost: 3000
Layout File Name: users
hint:
Response code of the request: show all the users

You should also notice a new line or two that we didn't see before, what is it (copy and paste, hint: after User Load) ?

Expand Down Expand Up @@ -685,5 +686,3 @@ Congrats, you're done, you've come pretty far since last week. Last week you wer
Now that you understand the basics of sending and retrieving data from a database, next week we can start to use some more rails practices to clean up your code and make life a little easier for yourself. If you were curious and decided to poke around in the views and controller for User, you might be a little surprised by how different it is, don't worry most of that is organization and is quite a bit harder to understand without the fundamentals we've just experienced.

The most important thing to take away from this MVCr exercise is that you can (and should) build everything incrementally. It's okay to not understand the bigger picture until after you're done. Taking many small steps and checking yourself after each is the best way to stay on course, no matter what the activity is.


1 change: 1 addition & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Product < ActiveRecord::Base
belongs_to :user
attr_accessible :name, :price
validates :name, :uniqueness => true
end
6 changes: 6 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<%= csrf_meta_tags %>
</head>
<body>
<%= link_to "Schneems Blog", "https://schneems.com" %>
<%= link_to "User List", users_path %>
<%= link_to "Products List", products_path %>

<%= params[:format] %>
<%= params.inspect %>

<%= yield %>

Expand Down
18 changes: 18 additions & 0 deletions app/views/products/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h2>Create View</h2>
<%= params[:product].inspect %>

<% product = Product.create(params[:product]) %>
<%= product.save %>
<%= product.inspect %>

<% if product.save %>
<h2> Congrats you created a new product</h2>
Your product looks like <%= product.inspect %>
<% else %>
<h2>Your product was not saved!! </h2>
<%= product.errors.full_messages %>
Please go back in your roswer and fix the problem
<% end %>

<br />
<%= product.errors.inspect %>
13 changes: 9 additions & 4 deletions app/views/products/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<h2> I AMA View </h2>
<p>
Find me in <%= Rails.root.join("app", "views", "products", __FILE__ ) %>
</p>
<% lots_of_products = Product.includes(:user).all %>
<ul>
<% lots_of_products.each do |product| %>
<li>
Product Name: ""<%= product.name %>"" costs $<%= product.price %>
Sold by <%= product.user.name %>
</li>
<% end %>
</ul>
13 changes: 13 additions & 0 deletions app/views/products/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h2>New Products View</h2>

<form method ='post' action='/products' >
<label>Name</label><br>
<input name="product[name]" size="30" type="text">

<br />
<label>Price</label><br>
<input name="product[price]" type="number">

<br />
<input type="submit" value="Create Product">
</form>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


get '/products' => 'products#index'
get '/products/new'=> 'products#new'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make these a little more readable, try the syntax:
get '/products/new', to: 'products#new'

post 'products' => 'products#create'

resources :users

Expand Down