Rails Devise fields_for不起作用



我正在使用Devise,但我认为这在这里并不重要。

我只是没有看到正在创建的fields_for。

这些是我的文件:

新.html.erb

<%= form_for(resource, :as => resource_name, html: { id: 'registration_form', class: '' }, :url => registration_path(resource_name)) do |f| %>
  <!-- Error messages -->
  <%= devise_error_messages! %>
    <%= render 'new_user_fields', f: f %>
    <!-- Fields for user-information -->
    <%= f.fields_for :user_info do |f| %>
      <%= render 'shared/user_info_fields_for_sign_up', f: f, resource: resource %>
    <% end %>
    <!-- Fields for driver-information -->
    <%= f.fields_for :driver do |f| %>
      <%= render 'shared/driver_fields_for_sign_up', f: f, resource: resource %>
    <% end unless resource.driver.nil? %>
  <!-- Submit button -->
  <%= f.submit "Sign up", class: "" %>
<% end %>

shared/_user_info_fields_for_sign_up.html.erb

<%= f.label t :label_gender %>
<%= f.collection_select :gender_id, Gender.all, :id, :type, class: '' %>
<%= f.label t :label_first_name %>
<%= f.text_field :first_name, class: "" %>
<%= f.label t :label_last_name %>
<%= f.text_field :last_name, class: "" %>
<%= f.label t :label_year_of_birth %>
<%= f.text_field :year_of_birth, class: "" %>
<%= f.label t :label_country %>
<%= f.select :country_alpha2, options_for_select: { Country.all }, class: '' %>
<%= f.label t :label_city %>
<%= f.text_field :city, class: "" %>
<%= f.fields_for :languageskills do |f| %>
  <%= render 'shared/languageskill_fields', f: f %>
<% end unless resource.user_info.languageskills.empty?%>
<%= link_to_add_fields t :label_add_language, f, :languageskills %>
<%= f.label t :label_interests %>
<%= f.text_field :interests, class: "" %>
<%= f.label t :label_about %>
<%= f.text_field :about, class: "" %>

RegistratiosController.rb

def new
    super
    resource.build_user_info
    resource.user_info.languageskills.build
    if params[:is_driver].to_i == 1
      resource.build_driver
    end
    Rails.logger.debug(resource.build_user_info.inspect)
end

控制台.log

Started GET "/en/sign_up?is_driver=1" for 127.0.0.1 at 2014-02-13 13:20:01 +0100
Processing by RegistrationsController#new as JS
  Parameters: {"is_driver"=>"1", "locale"=>"en"}
  Rendered registrations/_new_user_fields.html.erb (12.1ms)
  Rendered registrations/new.html.erb within layouts/application (27.8ms)
  Rendered layouts/_header.html.erb (2.8ms)
  Rendered layouts/_messages.html.erb (0.2ms)
  Rendered layouts/_footer.html.erb (0.6ms)
   (0.2ms)  begin transaction
   (0.1ms)  commit transaction
#<UserInfo id: nil, user_id: nil, first_name: nil, last_name: nil, year_of_birth: nil, city: nil, created_at: nil, updated_at: nil, gender_id: nil, interests: nil, about: nil, country_alpha2: nil>
Completed 200 OK in 117ms (Views: 96.5ms | ActiveRecord: 0.4ms)

加载_new_user_fields.html.erb没有任何问题。我已经将所有可能的符号插入到application_controller.rb中的 Design 的输入参数中。虽然这并不重要,对吧?

你能指出我正确的方向吗?我看不出我的错:S

刚刚找到了错误的来源,并将为其打开一个新帖子。

我打不来电话

resource.build_nested_model

在我的控制器中。但是当我在视图中调用它时,它有效。嵌套模型在传递到视图时似乎未保存到资源中。

链接到新线程

Rails 设计 在控制器中构建嵌套模型

相关内容

  • 没有找到相关文章

最新更新