Currently i have the following and am faced with pasting this to all forms... *yawn* <div class="required"> <label for="<%= form_name -%>_<%= :name -%>">Name</label> <br /> <%= f.text_field :name %> </div> <div class="optional"> <label for="<%= form_name -%>_<%= :description -%>">Description</label> <br /> <%= f.text_area :description%> </div> If i could find out if the attribute is required then i could create a form builder and DRy it all up. eg in test.rb def required_text if self.attribute.required_field return ''required'' end ''optional'' end then in a form builder have <div class="<%= test.required_text %>"> <label etc.... </div> -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Hi Adam,
I''m not sure what what the nicest solution is, but this line would
tell you if the model allows the field to be null or not:
Model.columns_hash[''column_name''].null
If that returns false, then that field cannot be null
So maybe make a helper based on that?
Hope that helps in some way
Jason
On 08/10/2006, at 4:49 PM, Adam Madd wrote:
>
>
> Currently i have the following and am faced with pasting this to all
> forms... *yawn*
>
> <div class="required">
> <label for="<%= form_name -%>_<%= :name
-%>">Name</label> <br />
> <%= f.text_field :name %>
> </div>
>
> <div class="optional">
> <label for="<%= form_name -%>_<%= :description
-%>">Description</
> label>
> <br />
> <%= f.text_area :description%>
> </div>
>
>
> If i could find out if the attribute is required then i could create a
> form builder and DRy it all up.
>
> eg in test.rb
>
> def required_text
> if self.attribute.required_field
> return ''required''
> end
> ''optional''
> end
>
>
> then in a form builder have
>
>
> <div class="<%= test.required_text %>">
> <label etc....
> </div>
>
> --
> 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-/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
-~----------~----~----~----~------~----~------~--~---
Alex Wayne
2006-Oct-08 06:52 UTC
Re: possible to find if attribute is a required attribute ?
Adam Madd wrote:> <div class="required"> > <label for="<%= form_name -%>_<%= :name -%>">Name</label> <br /> > <%= f.text_field :name %> > </div> > > <div class="optional"> > <label for="<%= form_name -%>_<%= :description -%>">Description</label> > <br /> > <%= f.text_area :description%> > </div>I''m not sure about getting AR to tell you the required fields, but at the very least you should be able to wrap those up into a helper to save the copy and pasting. Or even roll them into a custom form builder, perhaps. -- 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-/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 -~----------~----~----~----~------~----~------~--~---