I''ve run into a problem upgrading an app to rails 2.0.1. All of this
worked under 1.2.6, but I''m not sure if the problem is caused by a bug
or changed behavior in 2.0.1.
this routing:
map.resources :bands do |t|
t.resources :instruments
t.resources :instruments, :collection => {:review => :get}
end
generates this when i run rake routes
review_band_instruments GET /bands/:band_id/instruments/review
{:action=>"review", :controller=>"instruments"}
this method
review_band_instruments_path(1)
produces this path
/bands/1/instruments/review
which erroneously generates these parameters:
Parameters: {"action"=>"show",
"id"=>"review",
"controller"=>"instruments",
"band_id"=>"1"}
and this error message:
ActiveRecord::RecordNotFound (Couldn''t find Source with ID=review AND
(instruments.band_id = 1))
under 1.2, this all worked properly with the following parameters:
Parameters: {"action"=>"review",
"controller"=>"instruments",
"band_id"=>"1"}
Any help appreciated.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I''m not sure whether duplication is causing your problem, but
I''ve never
seen anything like this
map.resources :bands do |t|
t.resources :instruments
t.resources :instruments, :collection => {:review => :get}
end
In the apps that I''ve worked on so far (I''ve only been doing
Rails for a
little over 3 months), my partners and I have only found it necessary to
declare t.resources once, whether or not we also declare :member and
:collection.
map.resources :bands do |t|
t.resources :instruments, :collection => {:review => :get}
end
Does that make a difference?
Craig
On Dec 9, 2007 4:39 AM, bbebop
<wtberry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> I''ve run into a problem upgrading an app to rails 2.0.1. All of
this
> worked under 1.2.6, but I''m not sure if the problem is caused by a
bug
> or changed behavior in 2.0.1.
>
> this routing:
> map.resources :bands do |t|
> t.resources :instruments
> t.resources :instruments, :collection => {:review => :get}
> end
>
> generates this when i run rake routes
> review_band_instruments GET /bands/:band_id/instruments/review
> {:action=>"review", :controller=>"instruments"}
>
> this method
> review_band_instruments_path(1)
>
> produces this path
> /bands/1/instruments/review
>
> which erroneously generates these parameters:
> Parameters: {"action"=>"show",
"id"=>"review",
> "controller"=>"instruments",
"band_id"=>"1"}
>
> and this error message:
> ActiveRecord::RecordNotFound (Couldn''t find Source with ID=review
AND
> (instruments.band_id = 1))
>
> under 1.2, this all worked properly with the following parameters:
> Parameters: {"action"=>"review",
"controller"=>"instruments",
> "band_id"=>"1"}
>
> Any help appreciated.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Duplication of resources doesn''t cause the problem. The routes and paths get specified properly. The problem occurs when rails translates the URLs into the wrong params. On Dec 9, 7:03 am, "Craig Demyanovich" <cdemyanov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m not sure whether duplication is causing your problem, but I''ve never > seen anything like this > > map.resources :bands do |t| > t.resources :instruments > t.resources :instruments, :collection => {:review => :get} > end > > In the apps that I''ve worked on so far (I''ve only been doing Rails for a > little over 3 months), my partners and I have only found it necessary to > declare t.resources once, whether or not we also declare :member and > :collection. > > map.resources :bands do |t| > t.resources :instruments, :collection => {:review => :get} > end > > Does that make a difference? > > Craig > > On Dec 9, 2007 4:39 AM, bbebop <wtbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''ve run into a problem upgrading an app to rails 2.0.1. All of this > > worked under 1.2.6, but I''m not sure if the problem is caused by a bug > > or changed behavior in 2.0.1. > > > this routing: > > map.resources :bands do |t| > > t.resources :instruments > > t.resources :instruments, :collection => {:review => :get} > > end > > > generates this when i run rake routes > > review_band_instruments GET /bands/:band_id/instruments/review > > {:action=>"review", :controller=>"instruments"} > > > this method > > review_band_instruments_path(1) > > > produces this path > > /bands/1/instruments/review > > > which erroneously generates these parameters: > > Parameters: {"action"=>"show", "id"=>"review", > > "controller"=>"instruments", "band_id"=>"1"} > > > and this error message: > > ActiveRecord::RecordNotFound (Couldn''t find Source with ID=review AND > > (instruments.band_id = 1)) > > > under 1.2, this all worked properly with the following parameters: > > Parameters: {"action"=>"review", "controller"=>"instruments", > > "band_id"=>"1"} > > > Any help appreciated.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bbebop wrote:> Duplication of resources doesn''t cause the problem. The routes and > paths get specified properly. The problem occurs when rails translates > the URLs into the wrong params.Duplication is most certainly the problem. If you do ''rake routes'' you''ll see the routes listed in match order. Notice that you have this unnamed route: GET /bands/:band_id/instruments/:id {:controller=>"instruments", :action=>"show"} above this named route: review_band_instruments GET /bands/:band_id/instruments/review {:controller=>"instruments", :action=>"review"} Routes match in the order they are defined. However, the second time you call t.resources :instruments with the :collection option you re-define the named routes. So you are generating the latter route above but matching the former, ending up with the #show action. Take out the first route and all will be well. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Josh! On Dec 9, 2007, at 11:32 AM, Josh Susser wrote: bbebop wrote:> Duplication of resources doesn''t cause the problem. The routes and > paths get specified properly. The problem occurs when rails translates > the URLs into the wrong params.Duplication is most certainly the problem. If you do ''rake routes'' you''ll see the routes listed in match order. Notice that you have this unnamed route: GET /bands/:band_id/instruments/:id {:controller=>"instruments", :action=>"show"} above this named route: review_band_instruments GET /bands/:band_id/instruments/review {:controller=>"instruments", :action=>"review"} Routes match in the order they are defined. However, the second time you call t.resources :instruments with the :collection option you re-define the named routes. So you are generating the latter route above but matching the former, ending up with the #show action. Take out the first route and all will be well. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---