Required fields depending on the form

0

I need to specify what is required depending on which form is displayed.

I have a Template that has some Ex fields.:

// Model User

: name,: age,: address

No Create for the User, only: Name must be mandatory. After the User is created, it will have two links one will open a form in a modal requesting only the: age, and in that form the: age should be obligatory. And in the other link will also open a form in a modal requesting only the: address which in turn should also be mandatory in that form.

How would the best way be possible?

    
asked by anonymous 25.11.2015 / 23:00

3 answers

1

I think the best way to do this is to validate with JS (Javascript), using the Required = true tag in HTML and putting

  

validates: name,: age,: presence address: true

No Model

    
17.12.2015 / 14:51
0

You can create conditional methods in your model and treat conditional validations:

validates :campo, presence: true, if: campoo_obrigatorio?

def campo_obirgatorio?
 // retorno booleano
end
    
25.05.2017 / 16:52
-2

I did not test, but did not work like this?

  • Put all fields as required
  • In each controller action remove the methods you do not want

    def create
      if params[:user][:idade].blank?
        params[:user].delete(:idade)
      end
    
      if params[:user][:endereco].blank?
       params[:user].delete(:endereco)
      end
    end
    
  • 17.02.2017 / 20:03
    Possible permission problem ___ ___ erkimt Reading json correctly to generate the data for the chart (Ajax and Morris) ______ qstntxt ___

    link

    I am not able to return json via ajax, I tried with console.log but it is returning the function itself that I mounted

    %pre%

    How do I return the json I had ridden before?

    All this is to generate the graph, but it is not reading json correctly.

    I'm following the tutorial on this site

    link

        
    ______ azszpr99132 ___
    %pre%     
    ___