I have a general query page that contains the following: <% form_tag(search_url(@id), :method => :get) do %> <%= text_field_tag(:id, '''', :size => 25) %> <p> <%= submit_tag "Search Database" %> </p> <% end %> I want the URL to be serial_number/A1234 and it performs the search. That works in my controller. But the page wants to call index with a query string. I know and have as a hack redirect from index to show, but that just slows it down because of the redirect. I also can duplicate the code in both index and show, but that is not very DRY. The controller is this: # GET /search # GET /search.xml def index redirect_to(:action => ''show'', :id => params[:id]) unless params[:id].nil? end # GET /search/:id :id is search serial number # GET /search/:id.xml def show unless params[:id].nil? @items = tem.by_serial_number(params[:id]) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @items } end end end Also, is there a way to change the default parameter from id to something that is more intelligent like in this case "serial_number" or sn? Don French --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Don French
2008-Feb-10 19:37 UTC
Re: singular_path calling index instead of show using a GET
bump Any Ideas? Don French On Feb 9, 10:24 pm, Don French <dhf0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a general query page that contains the following: > > <% form_tag(search_url(@id), :method => :get) do %> > <%= text_field_tag(:id, '''', :size => 25) %> > <p> > <%= submit_tag "Search Database" %> > </p> > <% end %> > > I want the URL to be serial_number/A1234 and it performs the search. > That works in my controller. But the page wants to call index with a > query string. I know and have as a hack redirect from index to show, > but that just slows it down because of the redirect. I also can > duplicate the code in both index and show, but that is not very DRY. > > The controller is this: > > # GET /search > # GET /search.xml > def index > redirect_to(:action => ''show'', :id => params[:id]) unless > params[:id].nil? > end > > # GET /search/:id :id is search serial number > # GET /search/:id.xml > def show > unless params[:id].nil? > @items = tem.by_serial_number(params[:id]) > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @items } > end > end > end > > Also, is there a way to change the default parameter from id to > something that is more intelligent like in this case "serial_number" > or sn? > > Don French--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---