简体   繁体   中英

Ruby on Rails: How do I get rid of the ActiveRecord:ReadOnlyRecord error?

It's happening on teh lp.save line. Which is weird, because I have the same code else where (slightly different though) for re-sorting the link_pages.

the menu bars and link pages are a has and belongs to many relationship

this is in the menu_bar/destroy method

 @menu_bar.link_pages.each do |lp|
      lp.sequence = LinkPage::NOT_USED
      lp.save
    end

also, rails 2.3.8

If you loaded link_pages via an ARel :join query, you can probably get rid of the error by changing :join to :include.

A similar question with a more detailed answer was answered here .

You can also use :readonly => false in your find options.

Look at https://stackoverflow.com/a/960903/327786

It works if you use rails 2.3.15 at least.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM