Possible to find if attribute is a required attribute?

Currently i have the following and am faced with pasting this to all
forms… yawn

Name
<%= f.text_field :name %>
Description
<%= f.text_area :description%>

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

<label etc....

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

Adam M. wrote:

Name
<%= f.text_field :name %>
Description
<%= f.text_area :description%>

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.