Unfortunately, our Ruby Developer is out of town, and we have an issue that needs a workaround fix until he can return. I have been tasked with finding it.
I am attempting to access one of our database views, hr_accounts_view, that contains the necessary data we need to incorporate into our existing page, which relies on an entirely different table. All that we are attempting to pull in, is the Status column from our view, so I have done my very best to keep the model/controller/view as simple as possible.
My hr_account_view model:
class HrAccountView < ActiveRecord::Base
self.table_name = 'hr_accounts_view'
# belongs to :hr_account
belongs to :employee, foreign_key: :id
validates :Status, presence: true
class HrAccountViewsController < ApplicationController
@HrAccountView.Status = HrAccountView.Status
<%= display_text_field @HrAccountView.Status %>
There are a few conventions that may help:
Attributes (the model version of a column) are specified in lowercase. So:
validates :status, presence: true
Same for instance variables. E.g.:
def show @status = HrAccountView.Status end
I suspect that
HrAccountView.Status may also be wrong, though possibly not. We would need to see what else is going on in the controller. Typically there is some operation doing a
find on the model using a parameter value from the request.
The variable name in the controller and the view must match:
<%= display_text_field @status %>
In Ruby a capitalized string (e.g.
Status) is a constant, a lowercase string is a reference to a variable or a method. If prefixed with '@' it is a reference to an instance variable.