Skip to content

Commit

Permalink
supporting textarea in form_field
Browse files Browse the repository at this point in the history
  • Loading branch information
lackac committed Apr 29, 2010
1 parent cc087b6 commit 200d568
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions helpers.rb
Expand Up @@ -14,19 +14,28 @@ def require_user
end
end

def form_field(label, object, attribute, type="text")
def form_field(label, object, attribute, type=:text)
object_name = object.class.name.downcase
id = "#{object_name}_#{attribute}"
name = "#{object_name}[#{attribute}]"
error = object.errors[attribute]
error = %{<span class="error">#{error}</span>} if error
%{
<p>
<label for="#{id}">#{label}:</label>
<input type="#{type}" id="#{id}" name="#{name}" value="#{object[attribute]}"/>
#{error}
</p>
}
unless type.to_sym == :textarea
%{
<p>
<label for="#{id}">#{label}:</label>
<input type="#{type}" id="#{id}" name="#{name}" value="#{object[attribute]}"/>
#{error}
</p>
}
else
%{
<p>
<label for="#{id}">#{label}:</label> #{error}<br/>
<textarea id="#{id}" name="#{name}" rows="10" cols="60">#{object[attribute]}</textarea>
</p>
}
end
end
end

Expand Down

0 comments on commit 200d568

Please sign in to comment.