我有一个用户模型,其中包含一个带有布尔值的“电子邮件切换”列。我想在我的视图中创建一个按钮,允许用户“打开”和“关闭”他们的电子邮件。我无法获得提交按钮来更新用户模型中的值。
<%= form_for :user do |f| %>
<label>On</label>
<%= f.radio_button :email_switch, true %>
<label>Off</label>
<%= f.radio_button :email_switch, false %>
<%= f.submit "Save", :controller => "dashboard_emails", :action => "update", :method => "put" %>
<% end %>
class DashboardEmailsController < ApplicationController
before_filter :require_user
def index
end
def update
end
private
def require_user
@user = @logged_in_user
end
class User
field :email_switch, type: Boolean, default: false
end