In create controller you should put something like
 respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @model }
      format.json {render :json => @model}
    end
Also in you have to call it in the browser with .json in order to show
it in that format
if you just are callin normal it will never render out

On Fri, Mar 4, 2011 at 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.
>
>

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