Current Code
@current_site_name = 'SITENAME'
@current_site = Site.where(:name => @current_site_name)
@current_site_id = @current_site.id
Basically, the name column in our Site model is unique. We are selecting a row using the site name as a parameter.
I am returned: <ActiveRecord::Relation:0x59426bc1>
I understand that I cannot simply ask for @current_site.id but is there any way to put the ID of the single activerecord into the variable @current_site_id
Again, there will always be one active record.
As you’ve seen,
wherewill return anActiveRecord::Relation(a set of rows), even if there’s only one row that matches your criteria. You can make@current_sitebe assigned to the row you want by changing the line to this: