On 25 Oct 2011, at 14:03, "Lukas M." <[email protected]> wrote:
> Hi,
> i have a "place" model with 2 columns (id, name).
> I'm calling an external api which gives me data to create a new place
> object.
>
> I would like to add the address from the external place to the place
> object and render it as a json result, without storing it in the
> database.
>
> i don't get any errors, but the address never shows up within the json
> output. i've tried with attr_accessor but that didn't work either.
foo.to_json(:methods => [:attr1, :attr2])
Maybe? (assuming that foo.attr1 returns one of your extra attributes)
Fred.
>
> any hints?
>
> thanks
>
>
> ==========================================
> place.rb
>
> class Place < ActiveRecord::Base
> attr_accessor: address
> end
>
> ==========================================
> places_controller.rb
>
> external_api_place_data = @client.find(place_id)
> place = Place.new
> place.name = place.name
> place.id = place.id
>
> //not showing up in the json result
> place.address = external_api_place_data.address
>
> places = []
> places << place
>
> respond_to do |format|
> format.html # index.html.erb
> format.json { render json: places }
> end
>
>
>
> ==========================================
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.