ruby on rails - Dynamically set method on before_save -


In my controller, I want to force my instance method first with e-mail callback.

Do any

Edit:

Controller

This original code ..

pre> def amfupdate set_properties validate_record if params [: csv_header] [: validate_record] == "Y" # on this condition ... super end

if Status I want to set up a custom callback that is called before, but before saving the object.

I want to call this method first before I_save..but if the condition on the controller side is correct ..

in model

  Valid DEF _Record Self.csv_columns.each do | Csv_column | Self.errors.add_to_base (_ ("invalid column name # {csv_column.column_name}."))) \ Until self.model_name.constantize.column_names.include? (Csv_column.column_name) Ends  

I think you can find something like Are there. In the model:

Validate. Example | Example.csv_columns.each do | Csv_column | | Instance.class.column_names.include until instance.errors.add: csv_columns, "invalid column name # {csv_column.column_name}"? (Csv_column.column_name) End of End

It will be called

to update: with suggestions for conditional assumptions

Add a attribute for

  attr_accessor: some_condtional  

set it to Controller

  @ instance.some_conditional = true # Or false  

Then the verification now looks like this:

  Validate. Example | Example.csv_columns.each do | Csv_column | | Example.errors.add: csv_columns, "invalid column name # {csv_column.column_name}" until instance.class.column_names.include? (Csv_column.column_name) end if with example. Interval end  

or something like them. In other words, use the model to capture the state and transmit the logic


Comments