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?
2009/9/16 Aldo I. [email protected]:
 f.date_select :period, :order => [:day, :month, :year]
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
Where 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
Aldo I. 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
Amar D. wrote:
Aldo I. 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=”}
2009/9/17 Aldo I. [email protected]:
my errors:
parameters:
 “period(2i)”=>“9”},
 “authenticity_token”=>“lWLs2p54kCr4Ymwj9DVBIvtmkdGtwZ/R8uvXZw8Sx14=”}
What type is the column period in the database?
Colin
2009/9/17 Aldo I. [email protected]:
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
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.
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 I. [email protected]
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.