What am I doing wrong? I just want to create a simple form where I can enter the ID of a model and it take me to that model. I''m trying to place the form in the application layout, so I can use it from anywhere in my app. I''m using restful routes only. I keep getting this routing error when trying to create the form: ticket_url failed to generate from {:controller=>"tickets", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. Here''s my resource declaration (routes.rb): map.resources :tickets Here''s my "show" method in tickets_controller: def show begin @ticket = Ticket.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @ticket } end rescue ActiveRecord::RecordNotFound logger.error("Attempt to access invalid ticket_id => #{params[:id]}") flash[:warning] = "You have requested an invalid ticket." redirect_to tickets_path end end Here''s the form_tag I''m trying to use: <% form_tag ticket_path, {:id => ''jumpbox'', :method => :get} do %> <p> <label for="id"><em>Enter a ticket number:</em></label><br/> <%= text_field_tag ''id'', nil, :size => 8, :class => "textbox" %> <%= submit_tag ''Go'', :name => nil %> </p> <% end %> Thanks for any help! -- 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 -~----------~----~----~----~------~----~------~--~---
ticket_path is expecting you to pass the ID of the ticket you are looking for. Something like this: ticket_path(123) Run ''rake routes'' to get a good idea of what each named route is doing. What you need is something like this: # tickets_controller def search show end # routes.rb map.resources :tickets, :collection => { :search => :post } You can now GET or POST to /tickets/search or tickets_search_path. On Mar 7, 1:05 am, Jl Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> What am I doing wrong? I just want to create a simple form where I can > enter the ID of a model and it take me to that model. I''m trying to > place the form in the application layout, so I can use it from anywhere > in my app. I''m using restful routes only. I keep getting this routing > error when trying to create the form: > > ticket_url failed to generate from {:controller=>"tickets", > :action=>"show"} - you may have ambiguous routes, or you may need to > supply additional parameters for this route. > > Here''s my resource declaration (routes.rb): > > map.resources :tickets > > Here''s my "show" method in tickets_controller: > > def show > begin > @ticket = Ticket.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @ticket } > end > rescue ActiveRecord::RecordNotFound > logger.error("Attempt to access invalid ticket_id => > #{params[:id]}") > flash[:warning] = "You have requested an invalid ticket." > redirect_to tickets_path > end > end > > Here''s the form_tag I''m trying to use: > > <% form_tag ticket_path, {:id => ''jumpbox'', :method => :get} do %> > <p> > <label for="id"><em>Enter a ticket number:</em></label><br/> > <%= text_field_tag ''id'', nil, :size => 8, :class => "textbox" %> > <%= submit_tag ''Go'', :name => nil %> > </p> > <% end %> > > Thanks for any help! > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah, I ran ''rake routes'' to study the routing but I just didn''t think I''d have to add to it. I specified the ''get'' method to ticket_path with an ID param coming in...I don''t understand why that wouldn''t work. So the search method will now render the show method? or redirect_to? or what? Thanks for the help. On Mar 7, 1:33 am, Andrew Bloom <akbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ticket_path is expecting you to pass the ID of the ticket you are > looking for. Something like this: > ticket_path(123) > > Run ''rake routes'' to get a good idea of what each named route is > doing. > > What you need is something like this: > > # tickets_controller > def search > show > end > > # routes.rb > map.resources :tickets, :collection => { :search => :post } > > You can now GET or POST to /tickets/search or tickets_search_path. > > On Mar 7, 1:05 am, Jl Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > What am I doing wrong? I just want to create a simple form where I can > > enter the ID of a model and it take me to that model. I''m trying to > > place the form in the application layout, so I can use it from anywhere > > in my app. I''m using restful routes only. I keep getting this routing > > error when trying to create the form: > > > ticket_url failed to generate from {:controller=>"tickets", > > :action=>"show"} - you may have ambiguous routes, or you may need to > > supply additional parameters for this route. > > > Here''s my resource declaration (routes.rb): > > > map.resources :tickets > > > Here''s my "show" method in tickets_controller: > > > def show > > begin > > @ticket = Ticket.find(params[:id]) > > > respond_to do |format| > > format.html # show.html.erb > > format.xml { render :xml => @ticket } > > end > > rescue ActiveRecord::RecordNotFound > > logger.error("Attempt to access invalid ticket_id => > > #{params[:id]}") > > flash[:warning] = "You have requested an invalid ticket." > > redirect_to tickets_path > > end > > end > > > Here''s the form_tag I''m trying to use: > > > <% form_tag ticket_path, {:id => ''jumpbox'', :method => :get} do %> > > <p> > > <label for="id"><em>Enter a ticket number:</em></label><br/> > > <%= text_field_tag ''id'', nil, :size => 8, :class => "textbox" %> > > <%= submit_tag ''Go'', :name => nil %> > > </p> > > <% end %> > > > Thanks for any help! > > -- > > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
After updating my tickets resources in my routing config like Andrew suggested, does anyone know how I might pass the :id param to the show method from the new search method so I don''t have to re-write the code in the show method? All I want to do is reuse the show method...it''s doing exactly what I want my search method to do. Thanks for any help! -- 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 -~----------~----~----~----~------~----~------~--~---