Is it possible to use a custom form builder with form_tag? It would be nice to impose the same look and feel for all my forms, whether or not they are model forms. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 15, 4:30 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is it possible to use a custom form builder with form_tag? It would > be nice to impose the same look and feel for all my forms, whether or > not they are model forms.OK, so it appears that form_tag doesn''t support form builders. So how do most Rails applications keep their non-model forms DRY? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 16, 2008, at 12:02 PM, bigbanger wrote:> > On Jan 15, 4:30 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Is it possible to use a custom form builder with form_tag? It would >> be nice to impose the same look and feel for all my forms, whether or >> not they are model forms. > > OK, so it appears that form_tag doesn''t support form builders. So how > do most Rails applications keep their non-model forms DRY?Why would you have a form and not a model? You don''t have to make that model class inherit from ActiveRecord::Base and be associated with the database. Create a class that has the fields (attr_accessor) that you need and use form_for. (Full disclosure: I haven''t done this, but I''d be surprised if it didn''t work.) From http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000920 at the bottom of the entry. Customized form builders You can also build forms using a customized FormBuilder class. Subclass FormBuilder and override or define some more helpers, then use your custom builder. For example, let‘s say you made a helper to automatically add labels to form inputs. <% form_for :person, @person, :url => { :action => "update" }, :builder => LabellingFormBuilder do |f| %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= text_area :person, :biography %> <%= check_box_tag "person[admin]", @person.company.admin? %> <% end %> In many cases you will want to wrap the above in another helper, so you could do something like the following: def labelled_form_for(name, object, options, &proc) form_for(name, object, options.merge(:builder => LabellingFormBuiler), &proc) end If you don‘t need to attach a form to a model instance, then check out FormTagHelper#form_tag. Does that help you out? -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
On Jan 16, 10:05 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> Why would you have a form and not a model? You don''t have to make > that model class inherit from ActiveRecord::Base and be associated > with the database. Create a class that has the fields (attr_accessor) > that you need and use form_for. > > (Full disclosure: I haven''t done this, but I''d be surprised if it > didn''t work.)Rob, I thought about doing something like that, but wondered if there was a better way. But I think it *should* work and I''ll give it a try and post back. Thanks for the suggestion. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Anton J Aylward
2008-Jan-16 18:43 UTC
Not a form, but builder? (was: Custom form builders and form_tag?
I get the ''form_for'' I get ''partials'' But if I have a partial like <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= text_area :person, :biography %> <%= check_box_tag "person[admin]", @person.company.admin? %> which I have been wrapping for my ''edit.rhtml'' with a <% form_for(@person) do |f| %> <%= render :partial => ''form'' , :locals=>{:f => f}%> <%= submit_tag ''Save'' %> <% end %> Can I use that same partial/layout for a view? -- There are two ways to slide easily through life: to believe everything or to doubt everything; both ways save us from thinking. -- Alfred Korzybski --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---