Once again, I'm writing about a pop-up window issue and need some help.
Trying to insert a new record prior to the pop-up and other sorts of
things has proven to be a much bigger problem so instead I'll have a
default record that will serve as a placeholder for new pop-up window
values.
In my main form, if I'm editing an order, the order id is sent to the
pop-up window. Then my pop-up window uses that information. If it's a
new order, the pop-up window doesn't have an order id.
To work around this, I'd like to set a default order ID that I'll use
for new orders so that the pop-up window options work.
Have you tried making this special route a :collection route instead
of a :member route?
If it were a collection route then the :id would be optional... but it
might also solve the bigger problem more gracefully. In your popup
action you could have something like this:
Then your view could build the url either for insert (new_record?) or
update. If you're already taking advantage of the new Rails 'form_for
@ivar' then it should be done for you.
Have you tried making this special route a :collection route instead
of a :member route?
If it were a collection route then the :id would be optional... but it
might also solve the bigger problem more gracefully. In your popup
action you could have something like this:
Then your view could build the url either for insert (new_record?) or
update. If you're already taking advantage of the new Rails 'form_for
@ivar' then it should be done for you.
I will definitely try the route. Right now I'm using the DRY Forms
example in the new Advanced Rails Recipes book so I'd like to avoid
converting the forms back, but I may need to do that anyway to denote
required fields.
The DRY form recipe extends the FormBuilder so you'll get all the
freebies that the FormBuilder is already providing -- like the ability
to tell if you've got a new object to create or an existing object to
update. If you follow the logic presented in the recipe you should be
able to extend it to denote required fields, too. You should be able
to provide a 'required' attribute in a similar way they provide the
override for the label.
AndyV wrote:
If you follow the logic presented in the recipe you should be
able to extend it to denote required fields, too. You should be able
to provide a 'required' attribute in a similar way they provide the
override for the label.
I'm still learning my way around RoR. I see this in the DRY Forms
helper code:
Yes, you're in the right ballpark. There are a few different ways you
could go.
First, I'd recommend that you piggyback on that 'option' hash. I'd
probably use a value like 'required_field' or something like that.
From that point you have the options. One way to approach it would be
to use option[:required_field] to add a css class to the field.
Another option would be to just add a '*' to the label. Right before
the call to 'build_shell':
options[:label] ||= field.to_s.humanize # default value for label if
none was provide
options[:label] << " *" if options[:required_field] # Add asterisk if
requred