I searched for forum for something about this but couldn''t find anything. For example I have this in my view: (you enter start/end dates from dropdowns, pick a category and a report is generated.) <%= start_form_tag :action => ''display_report'' %> From: <%= date_select ''report'', ''date1'' %> <br /> To: <%= date_select ''report'', ''date2'' %> <br /> Category: <%= select(:report, :category_id, @categories) %><br /> <%= submit_tag ''Show Report'' %> <%= end_form_tag %> When I submit this form (back to the same action) all of the dropdowns are reset to default values, instead of what was selected. I haven''t had problems when editing a AR object though. These inputs aren''t related to an object, is that why? Thanks, Chris -- Posted via http://www.ruby-forum.com/.
Yes, that''s why. You have to save them in an instance variable, and put this value in the select (just like you would in PHP). Please tell me if you have any problems with it. Jules -- Posted via http://www.ruby-forum.com/.
Jules wrote:> Yes, that''s why. You have to save them in an instance variable, and put > this value in the select (just like you would in PHP). > > Please tell me if you have any problems with it. > > JulesHmm, I''m not quite sure on how to do this, can you give me an example? -- Posted via http://www.ruby-forum.com/.
Chris Sepic wrote:> Jules wrote: >> Yes, that''s why. You have to save them in an instance variable, and put >> this value in the select (just like you would in PHP). >> >> Please tell me if you have any problems with it. >> >> Jules > > Hmm, I''m not quite sure on how to do this, can you give me an example?I was able to get the category to change by creating a report object: class Report attr_reader :category_id attr_writer :category_id def initialize(cat_id) @category_id = cat_id end end I messed around with trying to get this to work with date_select, but no luck. Can this be done? If so how do I set date1 and date2? -- Posted via http://www.ruby-forum.com/.
Chris Sepic wrote:> Chris Sepic wrote: >> Jules wrote: >>> Yes, that''s why. You have to save them in an instance variable, and put >>> this value in the select (just like you would in PHP). >>> >>> Please tell me if you have any problems with it. >>> >>> Jules >> >> Hmm, I''m not quite sure on how to do this, can you give me an example? > > I was able to get the category to change by creating a report object: > class Report > attr_reader :category_id > attr_writer :category_id > > > def initialize(cat_id) > @category_id = cat_id > end > end > > I messed around with trying to get this to work with date_select, but no > luck. Can this be done? If so how do I set date1 and date2?Ok answering my post yet again, but I found one solution: class Report attr_reader :category_id, :date1, :date2 attr_writer :category_id, :date1, :date2 def initialize(cat_id, date1_year, date1_month, date1_day, date2_year, date2_month, date2_day) @category_id = cat_id.to_i @date1 = Date.new(date1_year.to_i,date1_month.to_i,date1_day.to_i) @date2 = Date.new(date2_year.to_i,date2_month.to_i,date2_day.to_i) end end So basically I had to create this class just so I could save my select lists. I supposed I could have also used select_year / select_month / select_day without this class by initializing a Date object in the controller, but then there would still be the problem of the category. If anyone has a better way of doing this let me know! -- Posted via http://www.ruby-forum.com/.