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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:56:21+00:00 2026-05-19T09:56:21+00:00

I am using Rails 3. And I’m wondering how to pass params to some

  • 0

I am using Rails 3. And I’m wondering how to pass params to some blocks in routes.rb.

What I’m trying to do is to make a catch all route, that check from slugs database the model name of it by the id.

After getting the model name i pluralize it to get the controller name.

match '/:id', :controller => proc { Slug.find_by_iid(params[:id]).model.pluralize }, :action => :show

The table slugs

model    iid
-----    -----
post     4d2c7de0c5abe7f8a9000007
item     4d2c7de0c5abe7f809000004

When I try to access some pages like /4d2c7de0c5abe7f8a9000007 I got this error:

Started GET "/4d2c7de0c5abe7f8a9000007" for
127.0.0.1 at 2011-01-12 00:04:31 +0200

ActionController::RoutingError (wrong constant name #<Proc:0x0000010337c310@):

Rendered /Users/amr/.rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)

The expected is to point to posts#view with iid: 4d2c7de0c5abe7f8a9000007

  • 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-19T09:56:22+00:00Added an answer on May 19, 2026 at 9:56 am

    proc returns a Proc, but match is expecting a string. You could try adding .call to have the proc return its value. Though I’m not sure if this will end up calling the proc each time or only when routes is loaded…

    EDIT

    Seems I was way off-base with my earlier response and comments. Maybe something like this?:

    match '/:id', :to => proc { |env|
      id = env["action_dispatch.request.path_parameters"][:id]
      model = Slug.find_by_iid(id).model
      controller = [model.pluralize.camelize,"Controller"].join.constantize
      controller.action("show").call(env)
    }
    

    Though this really ought to be defined in a library and included. Perhaps someone knows a better way?

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

Sidebar

Related Questions

using Rails 3.1.0.rc4, I'm trying to access a route helper in a javascript file
Using Rails 3.1. I have some pages that render same layout, except the contents
Using Rails v2.1, lets say you have an action for a controller that is
Using Rails 3.1.3 with Ruby 1.9.3p0. I've discovered that by default, Rails does not
When using Rails date_select with :prompt => true I see some very strange behavior
I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js .
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable
Using Rails 3.2 and ruby 1.9.3p0 I am trying out the gem delayed_job. I
Using Rails I'm trying to get an error message like The song field can't
Note: Using Rails 3.1 and current delayed_job gem. I have a User model that

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.