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 1027085
In Process

The Archive Base Latest Questions

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

I have a Place model that has both ‘city_name’ and ‘name’ as attributes. I

  • 0

I have a Place model that has both ‘city_name’ and ‘name’ as attributes. I would like to define a custom method that finds the place whose name matches the city_name for another place eg.

Place.name = “foo”
Place.city_name = “baz”

then Place.find_city gives the record where Place.name = “baz”. At the moment I’ve got something along the lines of:

def find_city
  Place.find_by_name("this.place.city_name")
end

View:

<%= link_to "#{@place.city_name}", place_path(@place.find_city) %>

This code currently doesn’t throw up any errors, but the link simply returns the current place record. Is this approach possible, and if so, what would be the best way to go about doing it? Thanks in advance!

  • 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-16T12:11:10+00:00Added an answer on May 16, 2026 at 12:11 pm

    Try something like this (assuming this method is part of model)

    def find_city
      Place.find_by_name(city)
      # param should be either 'city' or 'city_name',
      # I'm confused by your attribute naming
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model that, in my mind, has two show actions: A
I have an architectural question that has been bothering me. Codeigniter defines there model
I have two models: Activity and Place. The Activity model has a ReferenceProperty to
I have an ActiveRecord model that has a long string field. Actually, this string
So I have a User model that :has_many other models like Documents, Videos, Posts
I have a rails 3 app that has 2 different UIs that both share
I have a model type that was generated from a mysql table that has
In my string I have place holders like: ##NEWSLETTER## , ##FOOTER# ##GOOGLEANALYTICS## etc. Each
I have one requirement that i have to place the log file in the
In what directory do I have to place my themes.xml in order that my

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.