I''m unable to pass a subset of a form''s parameters to another method within the same controller. The error message is "wrong number of arguments (0 for 3)" and there aren''t any parameters listed. Here''s the controller code: class InfoController < ApplicationController def show_actual_forecast_data # parameters from the form data_type = params[:datatype] productnbr = params[:productlinenbr] start_date = params[:start_date] end_date = params[:end_date] detail_or_sum = params[:detail_sum] @time_search = TimePeriodSearch.new(data_type, productnbr, start_date, end_date, dtail_or_sum) if detail_or_sum == "detail" then if dtype == "actual" then redirect_to({:action => ''test_page''}, :datatype => data_type, :start_date => start_date, :end_date => end_date) end end end def test_page(datatype, start_date, end_date) @actual_data = Dailytotal.actual_data_sum(datatype, start_date, end_date) end end Here''s the TimePeriodSearch model: class TimePeriodSearch attr_accessor :datatype, :productnbr, :start_date, :end_date, :detail_or_sum def initialize(datatype, productnbr, start_date, end_date, detail_or_sum) @datatype, @productnbr = datatype, productnbr @start_date, @end_date = start_date, end_date @detail_or_sum = detail_or_sum end end Any feedback would be greatly appreciated. -- 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 -~----------~----~----~----~------~----~------~--~---
On Apr 20, 8:33 am, Paul Bednar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m unable to pass a subset of a form''s parameters to another method > within the same controller. The error message is "wrong number of > arguments (0 for 3)" and there aren''t any parameters listed....> def test_page(datatype, start_date, end_date) > @actual_data = Dailytotal.actual_data_sum(datatype, start_date, > end_date) > end > end... If test_page is an action, then it cannot have any parameters unless those parameters have default values. Either: def test_page @actual_data = Dailytotal.actual_data_sum(params[:datatype], params[:start_date], params[:end_date]) end Or: def test_page(datatype = params[:datatype], start_date params[:start_date], end_date = params[:end_date]) @actual_data = Dailytotal.actual_data_sum(datatype, start_date, end_date) end should work. Dan Manges http://www.dcmanges.com/blog --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Uh... redirect_to does not call another action... It does an http redirect... meaning new request... meaning no args are passed. If you want to call another action in the same controller, just call it... like any other method. b Dan Manges wrote:> On Apr 20, 8:33 am, Paul Bednar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I''m unable to pass a subset of a form''s parameters to another method >> within the same controller. The error message is "wrong number of >> arguments (0 for 3)" and there aren''t any parameters listed. > ... >> def test_page(datatype, start_date, end_date) >> @actual_data = Dailytotal.actual_data_sum(datatype, start_date, >> end_date) >> end >> end > ... > > If test_page is an action, then it cannot have any parameters unless > those parameters have default values. > > Either: > def test_page > @actual_data = Dailytotal.actual_data_sum(params[:datatype], > params[:start_date], params[:end_date]) > end > > Or: > def test_page(datatype = params[:datatype], start_date > params[:start_date], end_date = params[:end_date]) > @actual_data = Dailytotal.actual_data_sum(datatype, start_date, > end_date) > end > > should work. > > Dan Manges > http://www.dcmanges.com/blog > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ben Munat wrote:> Uh... redirect_to does not call another action... It does an http > redirect... meaning new request... meaning no args are passed. > > If you want to call another action in the same controller, just call > it... like any other method. > > bDan and Ben--thanks for your insightful feedback! It''s possible to pass parameters using redirect_to to another method in the same controller. Here''s what I did. 1. Fix the redirect_to code. redirect_to :action => "test_page", :aproductnbr => productnbr, :a_start_date => start_date, :a_end_date => end_date 2. Change the test_page method to the following def test_page @actual_data = Dailytotal.actual_data_sum(params[:aproductnbr], params[:a_start_date], params[:a_end_date]) end 3. Ignore the TimePeriodSearch model and @time_search, as they aren''t needed. Cheers, Paul -- 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 -~----------~----~----~----~------~----~------~--~---