nesfna
Last Updated: February 25, 2016
·
1.467K
· bartlomiejdanek
Bard2

Make ActiveRecord objects not readonly

When you get readonly object, for instance

_project = Project.accessible_by_user(current_user).find(params[:project_id])
_project.readonly? # => true

And you want to edit it, you have to add :readonly => false to find as second parameter.

_project = Project.accessible_by_user(current_user).find(params[:project_id], :readonly => false)
_project.readonly? # => false

find method can be replaced by all, first, last etc.

Say Thanks
Respond