KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jul-24 21:27 UTC
Re: Strange change in form_tag behavior from 2.0 to 2.1?
You know what it was??? The route somehow was not high enough up in the routes.rb file? I have no idea why this is as there''s not another route like this..but I just thought I might make someone''s day a little easier. Kathleen On Jul 24, 12:25 pm, "KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve used an approach frequently in the past where I create a method > in the model that when passed parameters from a selection form returns > a modified result set. > As an example the routine in the model looks like this; > > def self.find_by_search(params) (shortened for easy reading) > where = [] > unless params[:agency].blank? > where << "agency_id = :agency" > end > if where.empty? > find(:all, > :order => params[:order]) > else > find(:all, > :conditions => [where.join(" AND "), params], > :order => params[:order]) > end > end > > Then the controller uses this model/method to modify the result set > based on the user''s entries. > > def ecase_search > @title = "Search Cases" > return if params[:commit].nil? > @ecase = @account.ecases.find_by_search(params) > @ecases = @ecase.paginate :per_page => 8, > :page => params[:page] > render(:template => "evidence/ecases/index") > end > > The search form that is supposed to pass the params back to the > controller action looks like this; > > <% form_tag( ecase_search_path, :method => "get") do %> (shortened > for easier reading) > <div id="search" class="box" <%= ''style="display:none;"'' %> > > <table> > <thead> > <tr> > <th><%= "Search Field" %></th> > <th><%= "Search Value" %></th> > </tr> > </thead> > <tbody> > <tr> > <td><strong><%= "Agency Code" %></strong></td> > <% @agencies = @account.agencies.find(:all) %> > <% @agencies << @account.agencies.new(:id => > '''', :description => ''All'') %> > <td><%= select_tag(:agency, > options_for_select(@agencies.collect { |c| [ c.description, > c.id ] }), :style => "width:150px", :id => :indexselect) %></td> > </tr> > <tr> > <% @selections = %w(agency_id incident_id officer > evidences_count) %> > <td><strong><%= "Order By" %></strong></td> > <td><%= select_tag(:order, > options_for_select(@selections), :style => "width:150px", :id > => :indexselect) %></td> > </tr> > <tr> > <td><%= submit_tag "Find Results", :class => "submit" %></ > td> > <td colspan="1"></td> > </tr> > </tbody> > </table> > </div> > <% end %> > > The routing in routes.rb looks like this; > > map.ecase_search ''ecase_search'', :controller => ''evidence/ > ecases'', :action => ''ecase_search'' > > The error I get when I try this approach is; > > ActionController::MethodNotAllowed > Only get, head, post, put, and delete requests are allowed. > > This approach worked wonderfully in 2.0 but now fails in 2.1. I had a > similar problem in 2.1 when I found that nested tables had to be > called differently in the form_for such as (<% form_for([@account, > @agency]) do |form| % ) > Any thoughts are greatly appreciated. > Kathleen--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---