ruby - How to prevent Rails from creating empty rows on post -
ruby - How to prevent Rails from creating empty rows on post -
i have migration:
class createcourses < activerecord::migration def alter create_table :courses, :id => false |t| t.uuid :id, :primary_key => true, :null => false t.datetime :date_start, :null => false t.float :price, :null => false t.datetime :date_end t.text :description t.text :location, :null => false t.timestamps end end end
and have create
method in controller:
def create course of study = course.new(params[:course]) if course.save render :nothing => true else render "public/422", :status => 422 homecoming end end
right now, when create phone call create
method data, creates new empty row in course
table. want create sure object sent create course of study object, , location , cost (for example) not empty , exist.
i have asp.net mvc background, origin larn rails.
p.s how homecoming success 200 response on successful creation, instead of render :nothing => true
?
check model validations:
http://guides.rubyonrails.org/active_record_validations.html#validates-associated
but example:
class library < activerecord::base has_many :books validates_associated :books end
ruby-on-rails ruby ruby-on-rails-4
Comments
Post a Comment