试图执行嵌套对象形式。页面加载没有错误,但是当我发送它时,没有信息被保存到组织模型中。
SQL调用说这个..
Parameters: {"commit" => "save", "action"=>"update","_method"=>"put", "organization"=>{"likes_snacks"=>"0"}, ..
哪个是对的。通过打开和关闭复选框可以正确更改 1 和 0。但是我猜这些信息并没有保存到数据库中。有任何想法吗?
哈姆勒:
- form_for @user do |f|
= f.label :username
= f.text_field :username
.clear
- fields_for :organization do |org| unless @user.organizations.empty?
= org.label :likes_snacks, 'Like snacks?'
= org.check_box :likes_snacks
= f.submit 'save', {class => 'button'}
控制器:
def edit
@user = current_user
@organization = current_user.organizations.first
end
楷模:
组织.RB:
has_many :users, :through => :organizations_users
用户.RB:
has_many :organizations, :through => :organizations_users