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

  • Home
  • SEARCH
  • 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 7557601
In Process

The Archive Base Latest Questions

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

My controller is using the default RESTful routes for creating, adding, editing etc I

  • 0

My controller is using the default RESTful routes for creating, adding, editing etc

I want to change the default :id to use :guuid. So what I did was:

# routes.rb
resources :posts

# Post Model
class Post < ActiveRecord::Base
    def to_param  # overridden
        guuid
    end
end

This works but my modifed REST controller code has something like this

def show
  @post = Post.find_by_guuid(params[:id])
  @title = "Review"
  respond_to do |format|
    format.html # show.html.erb
  end
end

When I see this this code ..

Post.find_by_guuid(params[:id])

it would seem wrong but it works.
I don’t understand why I can’t write it out like this:

Post.find_by_guuid(params[:guuid])

Why do I still have to pass in the params[:id] when I’m not using it?
Looking for feedback on whether my approach is correct or anything else to consider.
Even though it works it doesn’t always mean it’s right.

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

    Type rake routes in your console, and check the output of the routes. You’ll see the fragment ‘:id’ in some of them, that’s where the params[:id] comes from. It’s a rails convention : when you use resources in your routes, the parameter is named id. I don’t know if you can change it (while keeping resources; otherwise you could just go with matching rules), but you shouldn’t anyway : even if it seems not very logic, it actually has sense, once your understand how rails routing works.

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

Sidebar

Related Questions

I'm using default route of mvc2 like {controller}/{action}/{id} . I want to access that
I'm using the Zend Framework to create an API I want to use apache
I'd like to use a class extending Controller as the default base type for
I am using the default Controller named Home. I have the following ActionResult: public
Iam using default settings for tank_auth installation. When I tried following statement in controller:
I need to present a modal tab bar controller using interface builder. I'd like
I have this function on my controller (Im using CodeIgniter) that reads the database,
Is there any way I can vary caching by a controller action parameter using
Im using a navigation controller and a normal view. In the view I'd like
Using a navigation controller, I am pushing a new view and setting the title

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.