0

In the Beginning Ruby: From Novice to Professional book Chapter 13 focuses on the frameworks that were most popular at the time of the writing; Rails, of course, featuring prominently.

The project that is used to introduce the concepts has a section which extends the generic application created with the rails command by adding a view_all method to the scaffold:

def view_all @Entries = Entry.all(:order => 'created_at DESC') end 

It also points out that the config/routes.rb file contains the following:

map.resources :entries 

and to update to be

map.resources :entries, :collection => { :view_all => :get } 

The problem is that my config/routes.rb file does not look exactly like that. It does not have the map. portion and just looks like

resources :entries 

I added the :collection... portion anyway.

The book then says to add the following to app/views/entries/view_all.html.erb

<% @entries.each do |entry| %> <h1><%= entry.title %></h1> <p><%= entry.content %></p> <p><em>Posted at <%= entry.created_at %></em></p> <% end %> <%= link_to 'Add New entry', new_entry_path %> 

I've done all of this, but when I attempt to run the "application" I get an error

Couldn't find Entry with id=view_all 

with the parameters as

{"collection"=>{"view_all"=>:get}, "id"=>"view_all"} 

Has anyone else either looked at the book and seen how it is a bit out of date and know a fix for this or at least have a general understanding of what I'm doing wrong?

1
  • If you start with rails, I would recommend to use the latest version..your version seems to be rails 2.xx and the latest is 4.0.0. - so there are two major releases between..definitly use the newest one! Better search for a new beginner guide like guides.rubyonrails.org.. Commented Aug 30, 2013 at 5:12

1 Answer 1

1

That book you are referring to is using older version of Rails.

In Rails 2, the syntax(as you've shown):

map.resources :entries, :collection => { :view_all => :get } 

In Rails 3, the syntax is:

resources :entries do get :view_all, on: :collection end 

Update:

Managed to grab the E-book version of second edition of the book and yes the second edition is using Rails 2.3.2. I think you should work on to find a newer book for yourself since you're using Rails 3 (based on the tag in question).

To get an understanding of routes, I think Rails Routing from the Outside In document is pretty verbose.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.