2

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

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352

2 Answers2

3

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.

Community
  • 1
  • 1
Scott
  • 17,127
  • 5
  • 53
  • 64
  • I didn't. @menu_bar is an active record with a habtm relationship with link_pages. – NullVoxPopuli Dec 27 '10 at 22:15
  • In that case, if you haven't found any other way of doing it, you could try changing your code to use an ARel query by querying with something like: MenuBar.include(:link_pages).where(:id => params[:id]).first ... (alter to match your scenario) – Scott Dec 27 '10 at 23:36
  • My final attempt at helping with an answer - I had this same 'ReadOnlyRecord' error a while ago, and I've looked back in my source code and I've found that I fixed my own issue with the following query (from my source): VendorStatus.joins(:order).where(:orders => {:code => order_code}).readonly(false).first Again, you will have to alter your own query to work along similar lines, but it may solve your issue. This is Rails 3 code and still works today. – Scott Dec 28 '10 at 12:07
0

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.

Community
  • 1
  • 1
TlmaK0
  • 3,578
  • 2
  • 31
  • 51