有一個基於Devise系統的用戶。
User_has_one:user_profile和user_profile_belongs_to:用戶
User_profile_has_one:語言,language_belongs_to:User_profile如何製作collection_select
在 'user_profiles' 表中,有知道一個叫 「LANGUAGE_ID」 列中的用戶在說什麼語言。
在'語言'表中,有一個名爲「名稱」的列。這可能像英文,西班牙文和語言類。
現在,我想補充的語言選擇我的色器件的編輯頁面
應該是這樣的下面。對?
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<% resource.build_user_profile if resource.user_profile.nil? %>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.fields_for :user_profile do |profile_form| %>
<div><%= profile_form.label :nickname %><br />
<%= profile_form.text_field :nickname %></div>
<div><%= profile_form.label :language_id %><br />
<%= profile_form.collection_select(language_id, @languages, language_id, name_ja) %></div>
<% end %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<br />
<div><%= f.submit "Update" %></div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
<%= link_to "Back", :back %>
更新!在registrations_controller.rb
def edit
@languages = Language.all
@countries = Country.all
@prefectures = Prefecture.all
@genders = Gender.all
end
謝謝,我改成了這一點,但它仍說「未定義的方法'映射'爲零:NilClass'。 – MKK 2012-07-15 05:59:36
我需要在我的控制器中寫些東西嗎?像@languages = ???或在視圖? – MKK 2012-07-15 06:02:26
我在我的registrations_controller.rb中沒有編輯方法,因爲它每次調用設計。但我想弄清楚請檢查我的更新! – MKK 2012-07-15 06:09:33