I can’t seem to figure out how to validate a few fields some1 please
help me out
model---------
class Record < ActiveRecord::Base
validates_presence_of :sw, :flex
end
controller------------
class RecordController < A;;icationController
def new
@record = Rrecord.new
@product = Product.find(params[‘product_id’])
end
def create
@Record.new(params[‘record’])
if @record.valid?
@record.save
redirect_to :action => ‘show’, :id = @record.product_id
else
render_action ‘new’
end
end
end
view--------------
<%= error_messages_for ‘Record’ %>
<input id=“record_sw” name = “record[sw]”,size = “40” type= “text” value
=" " />
<input id=“record_flex” name = “record[flex]”,size = “40” type= “text”
value =" " />
Now i know the record will save and be created just fine w/out checking
‘@record.valid?’, but when i do check, it fails (if the field is blank)
and the render_action ‘new’ complains that it is looking for the
“product_id”, which i understand because it is looking for it in the
controller. Why won’t this work, i’ve spent well more time than
allocated on such a small matter, please help!!!