0
我正在使用Devise,但我認爲這不是很重要。Rails設計fields_for不工作
我根本沒有看到fields_for被創建。
這些都是我的文件:
new.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 %>
共享/ _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
CONSOLE.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
中的設計輸入參數。雖然這並不重要,對吧?
您能否指點我正確的方向?我沒有看到我的錯誤:S