不可加工的复选框

时间:2016-05-10 11:03:39

标签: ruby-on-rails forms checkbox

我已经在这个问题上苦苦挣扎了2天,我想我慢慢开始失去理智。 我正在尝试以嵌套的形式更新'profiles'表的布尔'schedule_display'。除此复选框之外的所有内容都可以。目前状态html看起来像这样:

template<class F1, class F2>
struct LogCallbackF : LogCallback {
    F1 f1;
    F2 f2;
    LogCallbackF(F1 f1, F2 f2) : f1(std::move(f1)), f2(std::move(f2)) {}

    void sendLog(std::string msg) override { f1(msg); }
    void setErrorCode(int code) override { f2(code); }
};

template<class F1, class F2>
inline LogCallbackF<F1, F2> make_log_callback(F1 f1, F2 f2) {
    return {std::move(f1), std::move(f2)};
}

void process() {
    Engine engine;
    auto callback = make_log_callback(
        [](std::string a) { std::cout << a << '\n'; },
        [](int a) { std::cout << a << '\n'; }
        );
    engine.setCallback(&callback);
    engine.start();
}

提交后的参数看起来很好我认为:

<%= nested_form_for @profile, html: { multipart: true } do |f| %>
  <span class="picture">
    <%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png' %>
  </span>
  <%= f.label :description %>
  <%= f.text_field :description %>
  <%= f.label :schedule_display %>
  <%= f.check_box :schedule_display, {}, "true", "false" %>
  <%= f.fields_for :buttons %>
  <%= f.link_to_add "Add a button", :buttons %>  
  <%= f.submit "Save changes" %>
<% end %>

Schedule_display也在正确的地方进行了授权:

profile"=>{"description"=>"Dolor et exercitationem.", "schedule_display"=>"true", ... 

Profile模型的相应部分如下所示:

params.require(:profile).permit(:id, :description, :picture,
                                 :schedule_display, buttons_attributes: [

和更新方法很简单:

class Profile < ActiveRecord::Base
  belongs_to :user
  has_many   :buttons,  :dependent => :destroy
  accepts_nested_attributes_for :buttons, 
    reject_if: proc { |attributes| attributes['user_website_url'].blank? }, 
    :allow_destroy => true
  mount_uploader :picture, PictureUploader
  attr_accessor :schedule_display
  validates :description, presence: true, length: { maximum: 500 }

我尝试过这样的事情:

def update
  @user = User.find(params[:id])
  @profile = @user.profile
  if @profile.update_attributes(profile_params)
    flash[:success] = "Profile updated"
    redirect_to @user
  else
    render 'edit'
  end
end

使用这些turn_schedule_函数和简单的update_attribute(),但它也不起作用。

为什么不起作用?

0 个答案:

没有答案
相关问题