How to validate in a model, data from a controller

后端 未结 4 861
刺人心
刺人心 2021-01-19 03:15

So I have some data that gets pulled from another rails app in a controller lets call it ExampleController and I want to validate it as being there in my model before allowi

4条回答
  •  自闭症患者
    2021-01-19 03:55

    You can pass the data from the controller as a parameter to the validation method in the model.

    In your models/awizard.rb

    def valid_for_step_one?(some_external_data)
      #validation logic here
    end
    

    So that in your controller, you can can call:

    model.valid_for_step_one?(data_from_controller)
    

    It would also be good if you can give a description of the data you are getting from the controller. How is it related to the model awizard?

    Because another option is to set the external data as an attribute of the model. Then you can use it in your validation functions from there.

提交回复
热议问题