Hi LeonS,

When you use respond_with it's render result is always in format HTML
unless you specify the contrary thing in your route. For example:

http://localhost:3000/today_orders/15 # This way you will render the
HTML

http://localhost:3000/today_orders/15.json # This way you will render
the JSON instead the HTML

If you want to set by default to render in JSON format, in your routes
you could configure it like this:

resources :today_orders, :defaults => {:action => "create", :format =>
"json"}

Best,
Luis Galaviz

On Mar 4, 2:32 am, LeonS <[email protected]> wrote:
> Hi,
>
> I've got a relationship through a one_to_many :though relationship:
>
> Controller:
>
> class TodaysOrdersController < ApplicationController
>
>   respond_to :json
>
>   before_filter :require_user
>
>   authorize_resource :class => false
>
>   def create
>     @patient = Patient.find(params[:patient_id])
>     @todays_order_of_patient =
> DailyOrder.create_or_find_todays_order_for_patient @patient
>     respond_with(@todays_order_of_patient, :location => nil, :include
> => :courses)
>   end
> end
>
> Model:
>
> class DailyOrder < ActiveRecord::Base
>
>   # Relationships
>   has_many :course_orders
>   has_many :courses, :through => :course_orders
>
>   has_many :patient_orders
>   has_one :patient, :through => :patient_orders
>
>   def self.create_or_find_todays_order_for_patient(patient)
>     if(!patient.todays_order)
>       daily_order = DailyOrder.create
>       PatientOrder.create(:patient => patient, :daily_order =>
> daily_order, :order_for_date => Date.today)
>       daily_order
>     else
>       patient.todays_order
>     end
>   end
>
> end
>
> The rendering result of the controller response with something like
> that:
> {"marked_for_destruction"=>false, "changed_attributes"=>{},
> "attributes"=> {"additional_information"=>"....", "id"=>"594369222"},
> "readonly"=>false, "errors"=>{}, "previously_changed"=>{},
> "destroyed"=>false, "attributes_cache"=>{}, "new_record"=>false}
>
> But i want the "right"json output which looks  like that:
> {"additional_information"=>"....", "id"=>"594369222"}
>
> Do you know whats wrong here?

-- 
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.

Reply via email to