rubyonrailsin

A Ruby and Rails talk

Friday, April 2, 2010


[Rails] Re: "new" form as partial?

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

On Apr 2, 4:27 pm, Marian Steinbach <marian.steinb...@gmail.com>
wrote:

> Creating a certain type of database record is a very frequent task in
> my application (or at least it should be ;-)). So I want to be able to
> place the form for creating that database record in practically any
> view, not just the /mymodel/new view.

I'm sure you can refactor code to fit almost anything into a single
new/edit partial :) But in my small experience the models are
different enough so that having different views for different models
makes the code more readable. That said, I almost always share new
and edit for a model in a partial:

e.g. new.html.erb
<%= render( :partial => "form", :locals => { :buttonname => 'Add' } )
%>

edit.html.erb
<%= render( :partial => "form", :locals => { :buttonname =>
'Update' } ) %>

_form.html.erb
<%= error_message_on :lab, :base %>
<% form_for ..., do |f| %>
<%= f.submit buttonname %>
...
<% end %>

Ryan Bates has great screencasts on this sort of thing, and I found
his Mastering Rails Forms http://www.pragprog.com/screencasts/v-rbforms/mastering-rails-forms
($5 a video) to be a great start.

Craig

--
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

Subscribe feeds via e-mail

Blog Archive