问题描述:

I am trying to develop a Rails application for QuickBase for which there is no adapter. I checked online for the QuickBase adapter but it is not working as it is for a very old version of rails and the author told me that he no longer supports it.

I want to be able to use the Active Record and the associated concepts of a typical rails application, but intervene and modify how the create, update and show actions work. I have created the application to create a new record successfully. However, when I want to be able to edit the record, I have first modified the edit action to go to my own database and get the data into an active record object.

To create an empty Active Record I said $user = User.new

Then I populated all the attributes with the data from my custom database. But the form still shows the Create User button, instead of Update User button. Apparently, I guess this is because the persist? method is returning false as this is a "new" object. But I know this is not a new one. So how do I influence the @user object to think it is a persistent one?

Alternatively, is there a way I can create the blank @user object without the new function?

I have checked all over the place, but couldn't find any clue on how to accomplish this. Thank you so much for your help.

网友答案:

You can try calling @user.disconnect! after your call @user = User.new, which will keep ActiveRecord from trying to write to the database, but I'm not sure that will solve your problem.

The larger problem is that you're trying to fit a square peg into a round hole here. The entire point of ActiveRecord is to abstract the connection to a database. So without a database, what's the point?

I think your best solution would be to write your own QB adapter. It may not be as difficult as you think, since you already seem to know how to read/write to the database.

You can read more about how to do that here: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/AbstractAdapter.html

相关阅读:
Top