Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord::ReadOnlyRecord when using ActiveAdmin and Friendly_id
    text
    copied!<p>I started using ActiveAdmin recently in a project and almost everything works great but I'm having a problem when using it in combination with the friendly_id gem. I'm getting ActiveRecord::ReadOnlyRecord thrown for my forms [i believe] because of the friendly_id attribute whose ID is readonly:</p> <pre><code>{"utf8"=&gt;"✓", "_method"=&gt;"put", "authenticity_token"=&gt;"Rc5PmUYZt3BiLvfPQr8iCPPXlbfgjoe/n+NhCwXazNs=", "space"=&gt;{"name"=&gt;"The Kosmonaut", "address"=&gt;"8 Sichovykh Striltsiv 24", "email"=&gt;"info@somedomain.com"}, "commit"=&gt;"Update Space", "id"=&gt;"the-kosmonaut"} &lt;--- culprit </code></pre> <p>I'm guessing the last line is the culprit as it's a readonly attribute, it's not in my form but rather in the PATH</p> <p><a href="http://localhost:5000/manage/spaces/the-kosmonaut/edit">http://localhost:5000/manage/spaces/the-kosmonaut/edit</a></p> <p>How can I fix this from trying to update the ID?</p> <p>Form from in ActiveAdmin looks like this: </p> <pre><code> form do |f| f.inputs "Details" do f.input :name f.input :address f.input :email f.input :phone f.input :website end f.inputs "Content" do f.input :description f.input :blurb end f.buttons end </code></pre> <p>UPDATE: This doesn't work either so it's not the friendly_id?</p> <p>I tried using @watson's suggestion which should have worked but still got the same error ;-(</p> <pre><code>{"utf8"=&gt;"✓", "_method"=&gt;"put", "authenticity_token"=&gt;"Rc5PmUYZt3BiLvfPQr8iCPPXlbfgjoe/n+NhCwXazNs=", "space"=&gt;{"name"=&gt;"The Kosmonaut 23"}, "commit"=&gt;"Update Space", "id"=&gt;"6933"} </code></pre> <p><a href="http://localhost:5000/manage/spaces/6933/edit">http://localhost:5000/manage/spaces/6933/edit</a></p> <p>When I check the record in the console with record.readonly? it returns false</p> <p>UPDATE UPDATE: removing the scope_to fixes the problem.</p> <pre><code>scope_to :current_user, :unless =&gt; proc{ current_user.admin? } </code></pre> <p>Only problem is I need the scope_to to prevent users from seeing records they do not own. My guess is (as I'm assuming scope_to normally works with has_many) that my HABTM association causes some weirdness? Ie Users &lt;-- HABTM --> Spaces?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload