diff --git a/README.md b/README.md index 442e3db2..d7bc9005 100644 --- a/README.md +++ b/README.md @@ -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) ? @@ -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. - - diff --git a/app/models/product.rb b/app/models/product.rb index f89d1033..9bb2c131 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,4 +1,5 @@ class Product < ActiveRecord::Base belongs_to :user attr_accessible :name, :price + validates :name, :uniqueness => true end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 083ca544..b5bdceca 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,12 @@ <%= csrf_meta_tags %> + <%= link_to "Schneems Blog", "https://schneems.com" %> + <%= link_to "User List", users_path %> + <%= link_to "Products List", products_path %> + + <%= params[:format] %> + <%= params.inspect %> <%= yield %> diff --git a/app/views/products/create.html.erb b/app/views/products/create.html.erb new file mode 100644 index 00000000..5aa8e36b --- /dev/null +++ b/app/views/products/create.html.erb @@ -0,0 +1,18 @@ +

Create View

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

Congrats you created a new product

+Your product looks like <%= product.inspect %> +<% else %> +

Your product was not saved!!

+<%= product.errors.full_messages %> +Please go back in your roswer and fix the problem +<% end %> + +
+<%= product.errors.inspect %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 2a558f6c..e34fa1c5 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,4 +1,9 @@ -

I AMA View

-

- Find me in <%= Rails.root.join("app", "views", "products", __FILE__ ) %> -

+<% lots_of_products = Product.includes(:user).all %> + diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 00000000..728569bd --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,13 @@ +

New Products View

+ +
+
+ + +
+
+ + +
+ +
diff --git a/config/routes.rb b/config/routes.rb index 978665c9..1ade6c92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,8 @@ get '/products' => 'products#index' + get '/products/new'=> 'products#new' + post 'products' => 'products#create' resources :users