mardi 14 mai 2019

Can I make f.checkbox optional in Rails?

I have one form and checkbox inside of it

<%= form_for @user, user_update_path do |f| %>
  <%= Checkbox %>
  <%= f.check_box :checked, {}, true %>
<% end %>

The question is can I make new method inside my User controller "checked" like this:

def checked
    if params[:checked] == true
      true
    else 
      false
    end 
  end

which I will use as a param later instead of making new migration and adding checked param to User model. Now I'm getting an error "undefined method 'checked'" I need this to set rails settings




Aucun commentaire:

Enregistrer un commentaire