I have a rails application that has an admins model which has many users and users has_and_belongs_to_many materials. The problem is that for a specific user (for example user/show/2) I have a form on that page that posts to materials create action. In the create action here is what I am trying to do
def create
@material = @user.materials.create(material_params)
end
However, it won't work because @user is nil. This needs to associate a material with a user via the users_materials table (because of the has_and_belongs_to_many association). So, how would I define a material from a users page (user/show/:id) and be able to define a material for that user? What is a good way to do this in rails?
materials?