Custom field in form_for that is missing from the model

I want to pass a parameter to my controller, its a simple checkbox, but I don't know how to represent this in my model form_for

model, see this my opinion:

<%= form_for @finance,:html => { :id => 'go_finance' } do |f| %>    
    <br>
    Transferir de :<%= f.select :from_money, @places.map { |p| [p.place, p.id] } %>
    para: <%= f.select :to_money, @places.map { |p| [p.place, p.id] } %>
    <br>
    Entrada: <%= f.text_field :input,:id => "input",:placeholder => "Quanto foi ganho ?" %>
    Saída: <%= f.text_field :output,:id => "output",:placeholder => "Quanto foi gasto ?" %>
    <br>
    Nota: <%= f.text_area :note %>
    <%= f.submit %>
<% end -%>

      

I want to make an additional checkbox, but how can I do this, not an object in the model, but an object that needs to be checked in order to do an if else in the controller, if you don't check, please help me and thanks a lot, thanks

+3


source to share


2 answers


You can try using check_box_tag

<%= check_box_tag :my_attr %>



then just check the presence params[:my_attr]

in the controller. If exists in the controller params[:my_attr]

, check the box.

+5


source


Add random checkboxes with check_box_tag

:



<%= label_tag :rnd_boolean %>
<%= check_box_tag :rnd_boolean %>

# then in your controller
if params[:rnd_boolean]
  do_suff
else
  do_other_stuff
end

      

+1


source







All Articles