[英]How to save params when your saving for a different user in Ruby on Rails
I am building this page where teachers (a kind of user) can edit settings of their students. 我正在建立此页面,教师(一种用户)可以在此页面上编辑学生的设置。 Every student can tell their teacher what instrument they play and teachers can let their students know what chords they have mastered.
每个学生都可以告诉老师他们演奏什么乐器,老师可以让学生知道他们已经掌握了哪些和弦。
Student page PS friend = student 学生页面 PS朋友=学生
= form_for :friend_instrument do |f|
%br
%h4.media-heading.text-post.search-result.center Basic chords
%hr
.half
= f.label :c, "C chord"
= f.select :c, [['No', false], ['Yes', true]], {}, class: 'form-control'
.half
= f.label :d, "D chord"
= f.select :d, [['No', false], ['Yes', true]], {}, class: 'form-control'
.half
= f.label :e, "E chord"
= f.select :e, [['No', false], ['Yes', true]], {}, class: 'form-control'
.half
= f.label :f, "F chord"
= f.select :f, [['No', false], ['Yes', true]], {}, class: 'form-control'
.half
= f.label :g, "G chord"
= f.select :g, [['No', false], ['Yes', true]], {}, class: 'form-control'
.half
= f.label :a, "A chord"
= f.select :a, [['No', false], ['Yes', true]], {}, class: 'form-control'
.half
= f.label :b, "B chord"
= f.select :b, [['No', false], ['Yes', true]], {}, class: 'form-control'
= f.submit "Update #{instrument.name} chords #{friend.full_name} mastered", class: 'btn btn-primary form-control'
user_controller user_controller
def students
@instrument = Instrument.all
end
private
def user_attributes
params.require(:user).permit(:profile_picture, :cover_photo, :username, :full_name, :facebook_url, :featured_song, :soundcloud_url, :twitter_url, :location, :date_of_birth, :about, :website, :phone, :terms, :playlist_id, :subscribed, :password, :sort_user, :school_is, instrument_ids: [])
end
user model 用户模型
has_many :user_instruments, dependent: :destroy
has_many :instruments, through: :user_instruments
accepts_nested_attributes_for :instruments
instrument model 仪器型号
class Instrument < ActiveRecord::Base
has_many :user_instruments
has_many :users, through: :user_instruments
has_many :meeting_instruments
has_many :meetings, through: :meeting_instruments
end
user instrument model 用户仪器模型
class UserInstrument < ActiveRecord::Base
belongs_to :user
belongs_to :instrument
end
I tried to add user_instruments_attributes but no luck! 我试图添加user_instruments_attributes,但没有运气! Any help would be much appreciated.
任何帮助将非常感激。
You want to keep that on the students side of things. 您想把它放在学生的一边。 The change you want to make is to allow teachers to update the attributes of students.
您要进行的更改是允许教师更新学生的属性。 You want to use cancan or access granted (I like access granted) to set who can update what.
您想使用cancan或访问权限授予 (我喜欢授予访问权限)来设置谁可以更新内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.