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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:34:21+00:00 2026-05-15T12:34:21+00:00

I am a beginner when it comes to Ruby on Rails, so I need

  • 0

I am a beginner when it comes to Ruby on Rails, so I need a little bit of help. I started reading a basic tutorial recently, which was taught using Scaffolding. I made a “Clients” model: script/generate scaffold clients name:string ip_address:string speed:integer … Inside the clients_controller.rb file, there is a method called show:

  # GET /clients/1
  # GET /clients/1.xml
  def show
    @client = Client.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @client }
    end
  end

For queries, I’d go to localhost:3000/clients/{Enter the ID here}. Instead of searching with the ID are the argument, I’d like to search with another value, like ip_address or speed, so I thought all I would have to do is change :id to :ip_address in “@client = Client.find(params[:id])”. However, that does not work, so would someone please tell me how I can achieve a search with another parameter. Thanks!

  • 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-15T12:34:22+00:00Added an answer on May 15, 2026 at 12:34 pm

    This doesn’t work because of the way things are routed

    When you do something like

    map.resources :client (See config/routes.rb)

    This happens automatically when you use scaffold.
    It sets up routes based on the assumption you’re using an id.

    One of these routes is something like

    map.connect 'clients/:id', :controller => 'client', :action => 'show'

    So :id is passed as a parameter as part of the URL.

    You shouldn’t have the IP be the primary identifier unless they’re distinct – and even then it kind of messes with the RESTful routing.


    If you want to have the ability to search by IP, modify your index action for the clients

    def index
      if params[:ip].present?
        @clients = Client.find_by_ip_address(params[:ip]);
      else
        @clients = Client.all
      end
    end
    

    Then you can search by ip by going to clients?ip=###.###.###

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few years back, I started learning Ruby/Rails from some beginner's guide for Rails.
I am definitely a beginner when it comes to Objective-C! Any help would be
Im a bit of a beginner when it comes to javascript constructs. Im trying
I am a bit of a beginner when it comes to Vim and it
I am a beginner with Ruby on Rails. I have a question regarding organizing
Okay, a little preface: I am still a beginner when it comes to AJAX,
I am a beginner for Twisted. Recently, I am reading the book Twisted Network
I'm a beginner when it comes to pointers and recently for an assignment I
I'm a total beginner when it comes to computer languages, and was asked for
I am an absolute beginner when it comes to ActionScript and Flash. I am

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.