Friday, November 16, 2012

[Rails] Re: can split form_for into two parts?

I think what you are looking for is fields_for. This let's you put data in a different part the params hash. This allows you to either get those fields out of the fields for a given model or allows you to update more than one model or a nest model cleanly.

While the Javascript example is clever, I would caution against as it breaks your MVC design pattern putting logic in your view. Doing inline programming as a matter of course will leave the application difficult to maintain over time. 

For this case, the Javascript does not sound necessary.

On Thursday, November 15, 2012 7:06:13 PM UTC-7, Ruby-Forum.com User wrote:
> <button id="show_options">Show Options</button>
>
> f.field A
>
> f.field B, :class => 'optional'
>
> <script type="text/javascript">
> var hidden_fields = $$('.optional').invoke('hide');
> $('show_options').observe('click',
>   function(evt){
>     hidden_fields.invoke('toggle');
>   }
> );
> </script>
>
> Walter

Oh, thanks.  Simpler than I thought.

soichi

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HvMhq531yowJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate