I am trying to add some extra conditional logic to my editing action by passing params to where.
Whenever I use anything other than .find (params [: id], the undefined method for ActiveRecord :: Relation: Class
My code is below
Controller:
def edit @office = Office.where("id = ? AND company_id = ?", params[:id], @company.id ) end
View:
<%= simple_form_for @office, :url => settings_office_path, :html => { :class => "office_form" } do |f| %> <h1>Edit <%= @office.office_name %> Details</h1> <%= render :partial => 'form', :locals => { :f => f } %> <% end %>
I inferred a class for @office, which is ActiveRecord :: Relation. If I just use
@office = Office.find(params[:id])
the conclusion is Office.
I think this is a problem, but I donβt know how to fix it. Any ideas?
Edward ford
source share