patrick99e99
unread,Jul 11, 2012, 2:40:51 PM7/11/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to SimpleForm
Hi everyone,
So, I have a has_one association, and the model has
"accepts_nested_attributes_for" for that association... I also have a
validation requirement for the associate model object to be present...
So I have a form:
simple_form_for @user do
f.input :username
f.simple_fields_for :location do |location_form|
location_form.input :address, :label => "Location"
end
end
When I submit the form without a location, I see:
2 errors prohibited this user from being saved:
Username can't be blank
Location can't be blank
However, the actual html for the location input does not render a
wrapper with a field_with_errors class, nor is there a span tag with
"Can't be blank", as there is with the username input.
...
I thought perhaps I just needed to do:
f.simple_fields_for :location do |location_form|
location_form.input :address, :label => "Location"
f.error :location
end
Although, that does puts the span tag "Can't be blank" on the page, it
doesn't put it inside the location input wrapper... So I am wondering
how to do that? I tried passing it in as a block to the input, but
that didn't work either.
So I ended up doing:
f.simple_fields_for :location, Location.new do |location_form|
content_tag :div, :class => [:input, :string, :required,
(:field_with_errors if f.error(:location))] do
location_form.input :address, :label =>
"Location", :required => true, :wrapper => false
f.error :location
end
end
Which seems a little ridiculous, so I am assuming that must be a
better way to handle this..... Any suggestions?
-patrick