hi, i have a problem with date_select and and active_form plugin example: view: form_for( "contact", :url => { :action => "form_contact" } ) do |f| .... other code .... f.date_select :period, :order => [:day, :month, :year] .... other code .... end model: class FormContact < ActiveForm attr_accessor :name, :surname, :period, ...... ... validations end control: def form_contact @contact = FormContact.new(params[:contact]) respond_to do |format| if @contact.valid? .......... end end end when i submit the for wen is present the date_select i retrive an error controller like this: `@period(3i)'' is not allowed as an instance variable name why? -- Posted via http://www.ruby-forum.com/.
any idea? -- Posted via http://www.ruby-forum.com/.
2009/9/16 Aldo Italo <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > hi, > i have a problem with date_select and and active_form plugin > > example: > > > view: > form_for( "contact", :url => { :action => "form_contact" } ) do |f| > .... other code .... > f.date_select :period, :order => [:day, :month, :year] > .... other code .... > end > > > model: > class FormContact < ActiveForm > attr_accessor :name, :surname, :period, ...... > ... validations > end > > > control: > def form_contact > @contact = FormContact.new(params[:contact]) > respond_to do |format| > if @contact.valid? > .......... > end > end > end > > > > when i submit the for wen is present the date_select i retrive an error > controller like this: > > `@period(3i)'' is not allowed as an instance variable nameWhere is that error appearing, is it your code or some plugin? If it is your code what do you expect @period(3i) to do? Colin> > > why? > -- > Posted via http://www.ruby-forum.com/. > > > >
Aldo Italo wrote:> any idea?Check your params[:contact] how it passes check params period how it passed or you can do this thing make setter method combine this hash 3 value -- Posted via http://www.ruby-forum.com/.
Amar Daxini wrote:> Aldo Italo wrote: >> any idea? > > Check your params[:contact] how it passes > check params period how it passed > or you can do this thing make setter method combine this hash 3 valuemy errors: /...../vendor/plugins/active_form/lib/active_form.rb:17:in `instance_variable_set'' /...../vendor/plugins/active_form/lib/active_form.rb:17:in `[]='' /...../vendor/plugins/active_form/lib/active_form.rb:6:in `initialize'' /...../vendor/plugins/active_form/lib/active_form.rb:5:in `each'' /...../vendor/plugins/active_form/lib/active_form.rb:5:in `initialize'' /...../app/controllers/front/sections_controller.rb:60:in `new'' /...../app/controllers/front/sections_controller.rb:60:in `form_contact'' parameters: {"contact"=>{"name"=>"", "period(3i)"=>"17", "info"=>"", "phone"=>"", "newsletter"=>"0", "privacy"=>"0", "surname"=>"", "period(1i)"=>"2009", "email"=>"", "period(2i)"=>"9"}, "authenticity_token"=>"lWLs2p54kCr4Ymwj9DVBIvtmkdGtwZ/R8uvXZw8Sx14="} -- Posted via http://www.ruby-forum.com/.
2009/9/17 Aldo Italo <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Amar Daxini wrote: >> Aldo Italo wrote: >>> any idea? >> >> Check your params[:contact] how it passes >> check params period how it passed >> or you can do this thing make setter method combine this hash 3 value > > > my errors: > /...../vendor/plugins/active_form/lib/active_form.rb:17:in > `instance_variable_set'' > /...../vendor/plugins/active_form/lib/active_form.rb:17:in `[]='' > /...../vendor/plugins/active_form/lib/active_form.rb:6:in `initialize'' > /...../vendor/plugins/active_form/lib/active_form.rb:5:in `each'' > /...../vendor/plugins/active_form/lib/active_form.rb:5:in `initialize'' > /...../app/controllers/front/sections_controller.rb:60:in `new'' > /...../app/controllers/front/sections_controller.rb:60:in `form_contact'' > > > parameters: > > {"contact"=>{"name"=>"", > "period(3i)"=>"17", > "info"=>"", > "phone"=>"", > "newsletter"=>"0", > "privacy"=>"0", > "surname"=>"", > "period(1i)"=>"2009", > "email"=>"", > "period(2i)"=>"9"}, > "authenticity_token"=>"lWLs2p54kCr4Ymwj9DVBIvtmkdGtwZ/R8uvXZw8Sx14="} >What type is the column period in the database? Colin
> > What type is the column period in the database? >this is a form wich submit an email, there arent''t database for this model, i have used active_form plugin to obtain this. -- Posted via http://www.ruby-forum.com/.
2009/9/17 Aldo Italo <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > >> >> What type is the column period in the database? >> > > > this is a form wich submit an email, > > there arent''t database for this model, i have used active_form plugin to > obtain this.I''m out of my comfort zone in that case, I guess it is expecting FormContact to have a DateTime field called period. I don''t know how you would handle that. Colin
First, you do not need a plug-in to get a date in a form. The fact that you''re using one, though, is irrelevant to the issue. Next, look at the params hash which you''re getting. It clearly has the date as September 17, 2009, which is in the "period" hash as: "period(3i)"=>"17", "period(1i)"=>"2009", "period(2i)"=>"9" You have to understand that the "period" hash has three parts, identified as period(1i), period(2i), and period(3i), representing the year, month, and day, respectively. Accordingly, if your controller included something like: @p = params[:period] you would then be able to identify the respective portions of the date. So, what''s the problem? Sandy On Sep 17, 12:01 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/9/17 Aldo Italo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > > > > >> What type is the column period in the database? > > > this is a form wich submit an email, > > > there arent''t database for this model, i have used active_form plugin to > > obtain this. > > I''m out of my comfort zone in that case, I guess it is expecting > FormContact to have a DateTime field called period. I don''t know how > you would handle that. > > Colin
thanks to all for the answers. I have thought to use the plugin active_form because it seemed me a valid solution in order to validate the data from the form. http://github.com/cs/active_form But if but there are these problems with the select_date helper then I will use another road. -- Posted via http://www.ruby-forum.com/.
If you are trying to mass assign an attribute that does not exist to an instance of your model, you need to create a virtual attribute http://railscasts.com/episodes/16-virtual-attributes On Sep 18, 6:24 am, Aldo Italo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> thanks to all for the answers. > > I have thought to use the plugin active_form because it seemed me a > valid solution in order to validate the data from the form. > > http://github.com/cs/active_form > > But if but there are these problems with the select_date helper then I > will use another road. > > -- > Posted viahttp://www.ruby-forum.com/.