Brian Ablaza wrote in post #972628:
> I have an app that manages tapes. Each tape has a number (separate from
> the record ID in MySQL).
>
> When a tape is added, the number field can be filled in. But when the
> record is subsequently edited, the number should not be editable.
>
> Both the "new" and "edit" views include (render) the same form partial.
> What would be considered best practice here?
>
> 1. Logic in the partial that checks to see if the action is "new" or
> "edit", and changes the form appropriately
>
> 2. Two different partials.
>
> 3. Remove the partial rendering and just have the "new" and "edit" views
> be complete forms
It depends how different the forms are.
Also:
4. Create a helper function to take the logic out of the view.
5. Decompose the form into more partials.
>
> I'm also interested in the "Rails philosophy" behind any recommendation.
> For example, I'd think that choice 1 is frowned upon, because it puts
> logic in a view, which should be minimized.
I agree, though simple conditionals are usually OK in views IMHO.
> But that choice creates the
> least amount of duplication, so it may make the code easier to manage
> long term. Which idea takes precedence?
There are other ways to reduce duplication, so I think it's a false
choice.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
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.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment