Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom field in form_for which isn't in model

I want to pass a parameter to my controller, its a simple check box but I dont know how I introduce this in my form_for of a model, see this is my view:

<%= 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 a extra checkbox but how can I make this, no a object in model but a object some to check to make a if else in controller, if check if no check, please help-me and thanks a lot, thanks

like image 285
overallduka Avatar asked Feb 01 '13 13:02

overallduka


2 Answers

You can try to use check_box_tag

<%= check_box_tag :my_attr %>

then just check for a params[:my_attr] in the controller. If params[:my_attr] exists in the controller, then the checkbox is checked.

like image 165
jvnill Avatar answered Sep 28 '22 01:09

jvnill


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
like image 32
ichigolas Avatar answered Sep 28 '22 02:09

ichigolas