From ec0a3f1be3515bac3bd42771a07c53807fa5a1b9 Mon Sep 17 00:00:00 2001 From: Stewart Farley Date: Fri, 10 Jul 2015 08:50:59 -0700 Subject: [PATCH 1/4] week 4 hw pt 2 --- README.md | 17 ++++++++--------- app/views/products/index.html.erb | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) 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/views/products/index.html.erb b/app/views/products/index.html.erb index 2a558f6c..684780d8 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,3 +1,4 @@ +

Hello World

I AMA View

Find me in <%= Rails.root.join("app", "views", "products", __FILE__ ) %> From 7933ae18d92b1a2cc783999458a27bf3f374f8f0 Mon Sep 17 00:00:00 2001 From: Stewart Farley Date: Fri, 10 Jul 2015 10:00:59 -0700 Subject: [PATCH 2/4] homework section 4 --- app/views/products/index.html.erb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 684780d8..e34fa1c5 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,5 +1,9 @@ -

Hello World

-

I AMA View

-

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

+<% lots_of_products = Product.includes(:user).all %> + From a06f502b570e9994cd946fb50f969d3d35cc01c5 Mon Sep 17 00:00:00 2001 From: Stewart Farley Date: Fri, 10 Jul 2015 10:45:05 -0700 Subject: [PATCH 3/4] homework section 5 --- app/views/layouts/application.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) 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 %> From 44ad1648f5902e9cdaa35afbd836ff5268e701dc Mon Sep 17 00:00:00 2001 From: Stewart Farley Date: Fri, 10 Jul 2015 12:04:55 -0700 Subject: [PATCH 4/4] finsihed week 4 hw --- app/models/product.rb | 1 + app/views/products/create.html.erb | 18 ++++++++++++++++++ app/views/products/new.html.erb | 13 +++++++++++++ config/routes.rb | 2 ++ 4 files changed, 34 insertions(+) create mode 100644 app/views/products/create.html.erb create mode 100644 app/views/products/new.html.erb 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/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/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