更新设置与'语言'模型

时间:2017-04-27 17:21:50

标签: ruby-on-rails devise

使用设计构建Rails应用程序。用户可以在devise / edit.html.erb中编辑其个人资料页面上的所有信息(名称,描述等)。用户模型与语言模型有关联。我希望用户在从f.select编辑他们的个人资料时能够选择他们自己的语言。我该如何实现这一目标?

提前致谢。

Edit.html.erb:

<div class="panel-body">
  <div class="panel-body">
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
    <%= devise_error_messages! %>
    <div>
      <div class="form-group">
        <%= f.label :coach_id %>
        <%= f.select(:coach_id, User.where('is_coach = ?', true).pluck(:name, :id), {}, { :class => 'select2 form-control' }) %>
      </div>
      <div class="form-group">
        <%= f.label :description %>
        <%= f.text_area :description, class: 'form-control', rows: '5' %>
      </div>
      <div class="form-group">
        <%= f.label :facebook %>
        <%= f.text_field :facebook, class: 'form-control' %>
      </div>
      <div class="form-group">
        <%= f.label :twitter %>
        <%= f.text_field :twitter, class: 'form-control' %>
      </div>
      <div class="form-group">
        <%= f.label :image %>
        <%= f.file_field :image, class: 'form-control' %>
      </div>
      <div class="form-group">
        <%= f.label :header_image %>
        <%= f.file_field :header_image, class: 'form-control' %>
      </div>
    </div>
    <br>
    <%= f.submit 'Update Settings', class: 'btn btn-success' %>
    <% end %>
  </div>
</div>

架构:

create_table "users", force: :cascade do |t|
  t.string   "email",                  default: "",    null: false
  t.string   "encrypted_password",     default: "",    null: false
  t.string   "reset_password_token"
  t.datetime "reset_password_sent_at"
  t.datetime "remember_created_at"
  t.integer  "sign_in_count",          default: 0,     null: false
  t.datetime "current_sign_in_at"
  t.datetime "last_sign_in_at"
  t.inet     "current_sign_in_ip"
  t.inet     "last_sign_in_ip"
  t.datetime "created_at",                             null: false
  t.datetime "updated_at",                             null: false
  t.boolean  "admin",                  default: false
  t.boolean  "is_coach",               default: false
  t.text     "description"
  t.string   "image_uid"
  t.string   "header_image_uid"
  t.string   "facebook"
  t.string   "twitter"
  t.boolean  "featured"
  t.integer  "coach_id"
  t.string   "name"
  t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
  t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end

create_table "languages", force: :cascade do |t|
  t.string  "language_code"
  t.integer "user_id"
  t.index ["user_id"], name: "index_languages_on_user_id", using: :btree
end

create_table "languages_users", force: :cascade do |t|
  t.integer "user_id"
  t.integer "language_id"
  t.index ["language_id"], name: "index_languages_users_on_language_id", using: :btree
  t.index ["user_id"], name: "index_languages_users_on_user_id", using: :btree
end

用户

has_and_belongs_to_many :languages

语言

has_and_belongs_to_many :users

0 个答案:

没有答案