I am working on a Rails application, and I have several actions (#delete_later, #ban_later, etc.), where I set only one attribute from the request parameter (in particular, the field reason
to perform this action).
I was wondering if it was ok to do this:
def ban_later
@object.reason = params[:object][:reason]
@object.save
end
Or is it better to use strong parameters even in this situation?
def ban_later
@object.reason = object_params[:reason]
@object.save
end
private
def object_params
params.require(:object).permit(:permitted_1, :permitted_2, :reason)
end
Which of these solutions is the best? If none of them are, then what is the best solution for my problem?
Later Edit:
#ban_later, #delete_later status
, , params. , "pending_delete", #delete_later "pending_ban", #ban_later.
#save
, update_attributes
? , if @object.save
. ( ) , @object
.