Reputation: 2055
Here is my code
def get_suppliers
supplier= Supplier.where(:user_id=>params[:supplier][:user_id],:is_deleted => "false")
if supplier.present?
render :json => {"status_code" => "200", :suppliers => supplier}
else
render :json => {"status_code" => "400", :suppliers => "Record not found"}
end
end
// supplier value
#<ActiveRecord::Relation [#<Supplier id: 69, supplier_name: "raj", food_business_no: "", mobile: "9154441222", work_phone: "9155551222 ", email_id: "[email protected]", date: "2014-11-18", other_information: "--", street_name: "VGP ", image_user_id: 1140, province: "", city: "", pincode: " ", state: "Australian capital teritory", country: "Australia", user_id: 42, supplier_user_id: 4, is_deleted: false, deleted_at: nil, created_at: "2014-11-18 09:26:56", updated_at: "2014-11-18 09:26:56">, #<Supplier id: 72, supplier_name: "tester", food_business_no: "", mobile: "3548621102", work_phone: "3549928500 ", email_id: "[email protected]", date: "2014-11-21", other_information: "--", street_name: "sdf ", image_user_id: 1166, province: "", city: "", pincode: " ", state: "Australian capital teritory", country: "Australia", user_id: 42, supplier_user_id: 5, is_deleted: false, deleted_at: nil, created_at: "2014-11-21 11:49:15", updated_at: "2014-11-21 11:49:15">, #<Supplier id: 74, supplier_name: "bobby", food_business_no: "", mobile: "9792626506", work_phone: "9852525252 ", email_id: "[email protected]", date: "2014-11-27", other_information: "--", street_name: "VIP ", image_user_id: 1175, province: "", city: "", pincode: " ", state: "Australian capital teritory", country: "Australia", user_id: 42, supplier_user_id: 7, is_deleted: false, deleted_at: nil, created_at: "2014-11-27 06:49:25", updated_at: "2014-11-27 06:49:25">]
I am getting TypeError : nil is not a symbol
on this line
render :json => {"status_code" => "200", :suppliers => supplier}
in my production server , but works well in my localhost , development server.
Here is log :
I, [2014-12-13T07:32:18.950505 #8580] INFO -- : Started POST "/get_suppliers" for 182.73.35.250 at 2014-12-13 07:32:18 +0000
I, [2014-12-13T07:32:18.951363 #8580] INFO -- : Processing by SuppliersController#get_suppliers as */*
I, [2014-12-13T07:32:18.951436 #8580] INFO -- : Parameters: {"access_token"=>"xxxxxx", "supplier"=>{"user_id"=>"42"}}
I, [2014-12-13T07:32:18.954972 #8580] INFO -- : Completed 500 Internal Server Error in 3ms
F, [2014-12-13T07:32:18.956617 #8580] FATAL -- :
TypeError (nil is not a symbol):
app/controllers/suppliers_controller.rb:15:in `get_suppliers'
Upvotes: 2
Views: 1234
Reputation: 2055
I solved this issue , this caused because of there is no primary key in the table ,
This worked after i add primary key in the model
class Supplier < ActiveRecord::Base
self.primary_key = 'id'
......
....
end
Upvotes: 0
Reputation: 10398
supplier
is a local variable object. Kindly changes your code
Like
def get_suppliers
@supplier= Supplier.where(:user_id=>params[:supplier][:user_id],:is_deleted => "false")
if @supplier.present?
render :json => {"status_code" => "200", :suppliers => @supplier}
else
render :json => {"status_code" => "400", :suppliers => "Record not found"}
end
end
Sorry my Bad
Well may be you need to changestatus_code
to :status
Upvotes: 1