Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3677834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:16:11+00:00 2026-05-19T03:16:11+00:00

I am trying to add some more conditional logic to my edit action by

  • 0

I am trying to add some more conditional logic to my edit action by passing params into a where.

Whenever I use anything other than .find(params[:id], the error undefined method `model_name’ 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 outputted the class for @office which is ActiveRecord::Relation. If I just use

@office = Office.find(params[:id])

the output is Office.

I think this is the problem but don’t know how to fix it. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:16:11+00:00Added an answer on May 19, 2026 at 3:16 am

    The form expects a single record to be in the @office instance variable, the where-method doesn’t return a single record but a relation, which can be multiple records, once queried.

    The correct way is:

    @office = Office.where(:company_id => @company.id).find(params[:id])
    

    Or even better, if you’ve defined the relation:

    @office = @company.offices.find(params[:id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add some logic in this. But I am not sure
I'm trying to add some accessibility for screen readers into a Flash application, and
I'm trying to add some more features to this(Attach a file): http://digitarald.de/project/fancyupload/3-0/showcase/attach-a-file Does anybody
I'm trying to simply add TimeZone information back into a LocalDate before performing some
I'm trying to add some fancy text to a label, but I've run into
I am trying to add some more native error handling to an SSIS C#
Im trying to add some short file names to a Wise installer to fix
I am trying to add some error detection to a script that is used
I was trying to add some non-production test code by creating a 3rd partial
I am trying to add some WebAPI support to my asp.net 4 RC site,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.