Hi All
I''m having some issues with the following routes problem.
The routes.rb file ...
map.resources :users
map.connect ''/users/view_payments/:user_id'', :controller
=>
''users'', :action => ''view_payments''
The users_controller.rb file ...
def view_payments
@user = User.find[:params[:user_id]]
@payments = @user.payments
end
The routes list from a rake routes ...
/users/view_payments/:user_id
{:controller=>"users", :action=>"view_payments"}
The .../views/users/view_payments.html.erb file ...
<%= link_to ''View Payments'', :controller =>
''users'', :action =>
''view_payments'', :user_id => @user.id %>
Then the URL generated from the link_to ...
http://localhost:3000/users/view_payments/2
But this returns a 404 error
Any help/ideas appreciated
Cheers
Adrian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On Mon, Jan 26, 2009 at 1:08 PM, Adrian <AdrianLloydSmith-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi All > > I''m having some issues with the following routes problem. > > The routes.rb file ... > map.resources :users > map.connect ''/users/view_payments/:user_id'', :controller => > ''users'', :action => ''view_payments'' > > The users_controller.rb file ... > def view_payments > @user = User.find[:params[:user_id]] > @payments = @user.payments > end > > The routes list from a rake routes ... > /users/view_payments/:user_id > {:controller=>"users", :action=>"view_payments"} > > The .../views/users/view_payments.html.erb file ... > <%= link_to ''View Payments'', :controller => ''users'', :action => > ''view_payments'', :user_id => @user.id %> > > Then the URL generated from the link_to ... > http://localhost:3000/users/view_payments/2 > > But this returns a 404 error > > Any help/ideas appreciated > > Cheers > Adrian > > > >Firstly have you restarted the server, this has bitten me more than a few times. Otherwise try putting the more specific route first in the routes file. -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You need to define a member resource on the map.resources :users. For more information see the guide on routing on http://guides.rubyonrails.org On 26/01/2009, at 21:08, Adrian <AdrianLloydSmith-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi All > > I''m having some issues with the following routes problem. > > The routes.rb file ... > map.resources :users > map.connect ''/users/view_payments/:user_id'', :controller => > ''users'', :action => ''view_payments'' > > The users_controller.rb file ... > def view_payments > @user = User.find[:params[:user_id]] > @payments = @user.payments > end > > The routes list from a rake routes ... > /users/view_payments/:user_id > {:controller=>"users", :action=>"view_payments"} > > The .../views/users/view_payments.html.erb file ... > <%= link_to ''View Payments'', :controller => ''users'', :action => > ''view_payments'', :user_id => @user.id %> > > Then the URL generated from the link_to ... > http://localhost:3000/users/view_payments/2 > > But this returns a 404 error > > Any help/ideas appreciated > > Cheers > Adrian > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
try
map.resources :users, :member => {:view_payments => :get}
should work.
On Jan 26, 12:08 pm, Adrian
<AdrianLloydSm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi All
>
> I''m having some issues with the following routes problem.
>
> The routes.rb file ...
> map.resources :users
> map.connect ''/users/view_payments/:user_id'',
:controller =>
> ''users'', :action => ''view_payments''
>
> The users_controller.rb file ...
> def view_payments
> @user = User.find[:params[:user_id]]
> @payments = @user.payments
> end
>
> The routes list from a rake routes ...
> /users/view_payments/:user_id
> {:controller=>"users", :action=>"view_payments"}
>
> The .../views/users/view_payments.html.erb file ...
> <%= link_to ''View Payments'', :controller =>
''users'', :action =>
> ''view_payments'', :user_id => @user.id %>
>
> Then the URL generated from the link_to ...
> http://localhost:3000/users/view_payments/2
>
> But this returns a 404 error
>
> Any help/ideas appreciated
>
> Cheers
> Adrian
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Jan 26, 5:08 am, Adrian <AdrianLloydSm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All > > I''m having some issues with the following routes problem. > > The routes.rb file ... > map.resources :users > map.connect ''/users/view_payments/:user_id'', :controller => > ''users'', :action => ''view_payments'' > > The users_controller.rb file ... > def view_payments > @user = User.find[:params[:user_id]] > @payments = @user.payments > end > > The routes list from a rake routes ... > /users/view_payments/:user_id > {:controller=>"users", :action=>"view_payments"} > > The .../views/users/view_payments.html.erb file ... > <%= link_to ''View Payments'', :controller => ''users'', :action => > ''view_payments'', :user_id => @user.id %> > > Then the URL generated from the link_to ... > http://localhost:3000/users/view_payments/2 > > But this returns a 404 error > > Any help/ideas appreciated > > Cheers > AdrianAs others have said, you just need to define the custom action in your routes. But I might suggest a more restful approach: map.resources :users, :has_many => :payments Then you can use links like http://localhost:3000/users/2/payments This calls the index action of a Payments controller. You can look at params[:user_id] to know which user is involved. This way you don''t need any custom actions. Just a thought. Jeff switchingtorails.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks to all who responded. I decided to go with the more RESTful approach: map.resources :users, :has_many => :payments and use the index action on the payments controller. Cheers Adrian On Jan 27, 1:11 am, Jeff <cohen.j...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 26, 5:08 am, Adrian <AdrianLloydSm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All > > > I''m having some issues with the following routes problem. > > > The routes.rb file ... > > map.resources :users > > map.connect ''/users/view_payments/:user_id'', :controller => > > ''users'', :action => ''view_payments'' > > > The users_controller.rb file ... > > def view_payments > > @user = User.find[:params[:user_id]] > > @payments = @user.payments > > end > > > The routes list from a rake routes ... > > /users/view_payments/:user_id > > {:controller=>"users", :action=>"view_payments"} > > > The .../views/users/view_payments.html.erb file ... > > <%= link_to ''View Payments'', :controller => ''users'', :action => > > ''view_payments'', :user_id => @user.id %> > > > Then the URL generated from the link_to ... > > http://localhost:3000/users/view_payments/2 > > > But this returns a 404error > > > Anyhelp/ideas appreciated > > > Cheers > > Adrian > > As others have said, you just need to define the custom action in your > routes. > > But I might suggest a more restful approach: > > map.resources :users, :has_many => :payments > > Then you can use links like > > http://localhost:3000/users/2/payments > > This calls the index action of a Payments controller. You can look at > params[:user_id] to know which user is involved. This way you don''t > need any custom actions. > > Just a thought. > > Jeff > switchingtorails.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---