Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails How to pass params from controller to after_save inside model

I have a Rfq contoller i am creating new or updating existing Rfqs, when i create or update the object is saved, what i want is as i have number of quotes params i want to update the line_items table with the quotes in params[:quotes] in quote_price column after saving the Rfqs

i know its confusing, but who are ror-ish should have got some hint wat i want to ask.

like image 691
Prakash Sejwani Avatar asked Dec 04 '22 23:12

Prakash Sejwani


2 Answers

If you're trying to use the params hash in your model, you are violating principles of MVC. The model should stand alone with arguments. If you are trying to do the following:

# controller
Model.foo

# model
def foo
  params[:bar].reverse!
end

You should do the following instead:

# controller
Model.foo(params[:bar])

# model
def foo(foobar)
  foobar.reverse!
end
like image 152
sethvargo Avatar answered Dec 08 '22 06:12

sethvargo


Honestly if it deals with params, it's probably a good idea to put that type of logic in the controller, lest you muddle the responsibilities of the model and controller.

That is, in the controller:

if @foo.save
  # Update line_items using params[:quotes]
end
like image 33
Andy Lindeman Avatar answered Dec 08 '22 05:12

Andy Lindeman