views:

29

answers:

2

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

A: 

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 ;)

apeacox
those were just examples to show what i was trying to do. when the addresses are built, i pass the @addresses array elements in as :address_type. in my view, currently i have to render a.text_field :address_type to see the data, and i set it to be disabled then style it to appear not like a text field (ie no border, no background, etc)but i am looking for a better solution than that.
brewster
A: 

discovered the object method!

- form_for @addresses do |a|
  %h1= a.object.address_type
brewster