我应该如何将rails和simple_form用于嵌套资源?

我正在尝试同时使用另一个(嵌套)创建一个资源。 我正在使用Rails4和simple_form 3.0.0rc。 这是我的代码。
楷模:

class User < ActiveRecord::Base has_one :profile accepts_nested_attributes_for :profile end class Profile < ActiveRecord::Base belongs_to :user end 

控制器:

 class UsersController < ApplicationController def new @user = User.new @user.build_profile end def create user = User.new user_params user.save redirect_to root_url # @par =params end private def user_params params.require(:user).permit(:email, profile_attributes: [:name]) end end 

查看(新用户的表单)

        

当我提交表单时,创建动作重现这个参数:

 {"utf8"=>"✓", "authenticity_token"=>"dJAcMcdZnrtTXVIeS2cNBwM+S6dZh7EQEALZx09l8fg=", "user"=>{"email"=>"vasily.sib@gmail.com"}, "profile"=>{"name"=>"Vasily"}, "commit"=>"Create User", "action"=>"create", "controller"=>"users"} 

在调用’user_params’后,唯一剩下的就是

 {"email"=>"vasily.sib@gmail.com"} 

而且,正如您所看到的,“配置文件”没有任何内容,因此不会创建任何配置文件。
我究竟做错了什么?

对不起我的英语。

使用f.simple_fields_for而不是simple_fields_for

 <%= f.simple_fields_for :profile do |p| %> <%= p.input :name %> <% end %> 

在我的情况下,我有对象“书”属于“旅游”和“旅游”has_many“书籍”。

在方法“new”的“BookController”中,我找到了tour并初始化了book对象:

@tour = Tour.find(params[:tour_id])

 @book = Book.new 

这是创建图书的部分forms:_form.html.erb

 <%= simple_form_for [@tour, @book] do |f| %> <%= f.input :name, label: "Name"%> <%= f.input :NoReservations, label: "Number of Reservations" %> <%= f.input :email, label: "Email" %> 

Num of available places

<%= f.button :submit %> <% end %>