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 P.S. friend = student
= 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
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! Any help would be much appreciated.
accepts_nested_attributes_for :user_instruments
on user? And, to make sure, you haveb
,c
,d
, ect. boolean columns onuser_instrument
? – Mark Swardstrominstruments
in the user class,user_instruments
. You need accepts nested attributes_for :instrument in the user_instrument class. It only goes one level, it doesn't go through. – Mark Swardstrom