简体   繁体   中英

How to pass Strong parameters to Model in Rails 4

Is it has a way to pass Strong parameters from Controller to Model

My point is passing param1 and param2 which contain in strong_params to The Model after that I want to access to puts param1 and param2 that contain in strong_param which received from controller

Assume that I have value in param1 and param2 already

In Controller

def action
   @sender = someModel.new()
   @sender.var_tunnel(strong_params)
end

private
def strong_params
   params.require(:stp).permit(:param1, :param2)
end


In someModel

def var_tunnel(stong_params)
    puts param1
    puts param2
end


Thanks for Advance

In this case you can access to the params in stong_params in your model like a Hash. So

def var_tunel(stong_params)
    puts stong_params[:param1]
    puts stong_params[:param2]
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM