Skip to content

Commit e0323c5

Browse files
author
Jed Schneider
committed
Rails 4 routing and attr_accessible changes
* Routing ** Rails 4 moved the root example from bottom to top of routes file ** the static index.html page is now a dynamic file at welcome#index and not a static file in public * attr_accessible ** Rails 4 has moved Mass Assignment responsibilities to an external gem ** In order to mass assign object attributes through a model you have to add the strong_paramters gem
1 parent c0da354 commit e0323c5

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

sites/curriculum/hooking_up_votes_and_topics.step

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ goals {
1717
}
1818

1919
steps {
20+
step 'Edit the Gemfile' do
21+
message "In order to save votes through the Topic model we must allow Rails to whitelist specific attributes for each model."
22+
message "In Rails 4, this functionality is provided in a separate gem. We need to install that gem in order to save the votes."
23+
message "Open the `Gemfile` in your text editor. Under the declaration for the `rails` gem add the following line of code:"
24+
25+
source_code :ruby, <<-RUBY
26+
gem 'strong_parameters'
27+
RUBY
28+
end
29+
30+
step "Apply the Gemfile changes" do
31+
console "bundle install"
32+
end
2033

2134
step {
2235
message "Edit `app/models/topic.rb` so that it looks like this:"

sites/curriculum/setting_the_default_page.step

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,12 @@ goals {
1313
steps {
1414

1515
step "Add a root route" do
16-
message "Open `config/routes.rb`. Near the end of the file but before the final end add `root :to => 'topics#index'`. When you are done the last few lines should look like this:"
16+
message "Open `config/routes.rb`. Search the file for 'root' (near the top) uncomment that line and change it to read `root 'topics#index'`. When you are done the line should look like this:"
17+
end
1718

1819
source_code :ruby, <<-RUBY
19-
root :to => 'topics#index'
20+
root 'topics#index'
2021
RUBY
21-
end
22-
23-
step "Remove the static welcome file" do
24-
25-
message " You also need to remove the welcome aboard page for the new route to work."
26-
27-
console "git rm public/index.html"
28-
29-
end
3022

3123
step "Confirm your changes" do
3224
message "Go back to <http://localhost:3000/>. You should be taken to the topics list automatically."
@@ -36,7 +28,7 @@ root :to => 'topics#index'
3628
explanation {
3729

3830
message <<-MARKDOWN
39-
* `root :to => 'topics#index'` is a rails route that says the default
31+
* `root 'topics#index'` is a rails route that says the default
4032
address for your site is `topics#index`. `topics#index` is the topics
4133
list page (the topics controller with the index action).
4234
* Rails routes control how URLs (web addresses) get matched with

0 commit comments

Comments
 (0)