using form data as text
i am trying to use form data outside of just form elements. i want to show form data as normal text.
controller:
@addresses = ['Billing', 'Shipping']
@addresses.each do |a|
addresses.build(:address_type => a)
end
then within my form...for example...(haml)
- fields_for :开发者_运维技巧addresses do |a|
a.address_type #to just render 'Billing', etc.
or...
- fields_for :addresses do |a|
%div{:class => a.address_type
would i need to make a custom formbuilder method? or is there an existing way
can't understand what you're looking for. that code doesn't seem correct at all. if @addresses is an array of elements, how do you expect it has any ActiveRecord methods?
EDIT: if you want to render just the data, even if the object is not saved, it's not a problem: in the controller you'll build the object:
...
addresses.build(:address_type => a)
...
then, in the view, use that data:
<some tag>
<%= @object.address_type %>
</some tag>
With a better example, I can explain better, but I hope you understand ;)
discovered the object method!
- form_for @addresses do |a|
%h1= a.object.address_type
精彩评论