I am new to rails and I have a task asking me to let a page admin to send invitations for regular users to be admins with him I implemented the part to reply to the invitations but I am stuck in an error and please tell me if I am on the right way here is my code for the invitation method
def invite
inviteUser = {"user_id" => current_user.id,"magazine_id" => params[:id]}
CollaborationInvitation.create(inviteUser)
@magazine = Magazine.find(params[:id])
redirect_to :back
end
Here is my model for the invitation:
class CollaborationInvitation < ActiveRecord::Base
belongs_to :user
belongs_to :magazine
end
Model for page:
class Magazine < ActiveRecord::Base
mount_uploader :image, ImgUploader
has_many :articles
acts_as_followable
has_and_belongs_to_many :users
errors[:image] << 'should be less than 5MB' if image.size > 5.megabytes
validates :name, presence: true
validates :image, presence: true
validate :image_size
end`
And the routes:
routes`member do
put 'follow' => 'magazines#follow'
put 'unfollow' => 'magazines#unfollow'
put 'invite' => 'magazines#invite'
end
error : No route matches [GET] "/magazines/3/invite" and when I changed the route from put to get
I get this error: unknown attribute 'user_id' for CollaborationInvitation
.