it is happening because of strong_parameter
, you have to pass permit
in forum
method .
Add attribute to User table in Controller create [duplicate]
-
18-10-2022 - |
Question
I want my logged in user to be able to create a new "forum". When they fill out the information in the form and click submit it will add 'admin' to their user table.
def create
@forum = Forum.new(forum)
respond_to do |format|
if @forum.save
format.html { redirect_to @forum, notice: 'Forum was successfully created.' }
format.json { render action: 'show', status: :created, location: @forum }
format.json { current_user.update_attribute :admin, true }
else
format.html { render action: 'new' }
format.json { render json: @forum.errors, status: :unprocessable_entity }
end
end
end
I thought this would work but when I try it I get
ActiveModel::ForbiddenAttributesError
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow