I'm upgrading my application from Rails 2.3.11 to 3.1.1. After
updating my routes file with the new syntax, I'm seeing a change in
behavior of the link_to method when passing an ActiveRecord object as
the link destination.

Here is an example of an old (non-RESTful) route from my 2.3
application's routes.rb:

map.with_options :controller => 'widget' do |widget|
widget.widget 'widget/show/:id', :action => 'show'

Here is what this route became in my 3.1 file:

controller :widget do
scope "widget" do
match "show/:id", :action => "show", :as => :widget

The output of `rake routes` is similar. 2.3:

widget /widget/show(/:id)
{:controller=>"widget", :action=>"show"}


widget /widget/show/:id(.:format)
{:action=>"show", :controller=>"widget"}

What's different is that now my link_to calls that look like this:

link_to("Text", @widget_object)

Produce this error message:

"Routing Error: No route matches
{ :controller=>"widget", :action=>"show", :id=>#<Widget id:
123, .....> }"

After seeing this passage in the Rails Guides:

"<%= link_to "Magazine details", @magazine %>...This allows you to
treat instances of your models as URLs, and is a key advantage to
using the resourceful style."

my guess is that Rails 2.3 happily handled my link_tos because my
named route was widget_path/widget_url (changing the name would cause
my 2.3 app's link_tos to break as well), but Rails 3 insists on
RESTful/resourceful routes if you're going to use this link_to style.

Is that right? I've started refactoring and adding the necessary
RESTful routes to make my link_tos work again — with good results —
but I want to confirm that I really understand the problem.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
postedNov 18, '11 at 9:14a
activeNov 18, '11 at 9:14a

1 user in discussion

William: 1 post



site design / logo © 2022 Grokbase