ruby on rails - Model custom validation passing true even though it is not -


i'm confused this. model has following custom validation:

def custom_validation     errors[:base] << "please select @ least 1 item" if @transactionparams.blank? end 

basically it's checking make sure parameters belonging different model not blank.

def request_params     @requestparams = params.require(:request).permit(:detail, :startdate, :enddate)      @transactionparams = params["transaction"]     @transactionparams = @transactionparams.first.reject { |k, v| (v == "0") || (v == "")} end 

if it's not blank, happens record saved, , kinds of other things happen.

def create     request_params     @request = @user.requests.create(@requestparams)     if @request.save         ...     else         render 'new'     end end 

if record not saved, re-rendered new view shows errors stopped @request being created. problem whether or not @transactionparams.blank? true or false, record fails save, , checked puts in log.

what's happening? read through docs because thought maybe custom validators couldn't used on other variables... that's not case...

thanks!

ok read on related articles. it's bad practice ever access variable controller in model. that's why... if put puts inspection in model not controller, @transactionparams nil.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -