Reputation: 11
I generated a scaffold against a legacy SQL Server database view that has a text primary key with no id column. I have set_primary_key "Gift_ID" in the model but Im getting an error on the show method.
I can list the records okay but when I click on the show link, it errors out. It appears to be using id to look up the record even though I have set_primary_key in the model. Here is the complete text of the error displayed;
NoMethodError in PledgesController#show
undefined method `eq' for nil:NilClass
Rails.root: /home/steve/RubymineProjects/otatest
Application Trace | Framework Trace | Full Trace
app/controllers/pledges_controller.rb:16:in `show'
Request
Parameters:
{"id"=>"PL-24681"}
Show session dump
Show env dump
Response
Headers:
None
Can anyone shed some light on why it is still trying to use "id" as the key? Thanks for any help!
Upvotes: 0
Views: 319
Reputation: 11
I solved my problem, so I thought I'd answer my own question in case it helps someone else;
I gave up on using the set_primary_key option in the model and added an "id" field to the view in my legacy system (SQL Server) using a key field in the data. That solved the id problem.
I also found that the generated scaffolding field names are case sensitive. So I used the view to set all field names to lowercase. You could make sure your scaffolding case matches the legacy field names, but I found that it's easier to just set them all to lower case.
One more thing; I had a few legacy boolean fields that had a "?" on the end of the field name, the scaffolding did not like that either, so I removed the "?" in the view.
Bottom line, building a Rails app on top of a legacy system has it's challenges. I discovered most my problems by migrating the table to the legacy database and examining the way it created the fields then modifying my view to match.
Upvotes: 1