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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:27:52+00:00 2026-05-25T16:27:52+00:00

This is my route: scope :username do resources :feedbacks end So when I go

  • 0

This is my route:

scope ":username" do
  resources :feedbacks
end

So when I go to mydomain.com/test/feedbacks/10 it shows the correct feedback with id=10 that belongs to username=test.

But, if I go to mydomain.com/test2/feedbacks/10 it shows me the same feedback with id=10, which does NOT belong to username=test2.

How do I restrict this from happening?

I am using the Vanity gem to give me the username in the URL, this is what that route looks like:

controller :vanities do 
    match ':vname' => :show, :via => :get, :constraints => {:vname => /[A-Za-z0-9\-\+\@]+/}
  end

Edit 1:

That is to say, for clarity’s sake, when I go to mydomain.com/test/feedbacks/10 and /test2/feedbacks/10, it shows me the same view for the same record (in which case, the latter version would be wrong because it should be telling me that no such record exists, but it’s not. It is just displaying the correct record for test/feedbacks/10).

Edit 2:

Here are the logs of both requests:

The right request

Started GET "/test-3/feedbacks/7" for 127.0.0.1 at 2011-09-14 02:48:15 -0500
  Processing by FeedbacksController#show as HTML
  Parameters: {"username"=>"test-3", "id"=>"7"}
  Feedback Load (0.5ms)  SELECT "feedbacks".* FROM "feedbacks" WHERE "feedbacks"."id" = ? LIMIT 1  [["id", "7"]]
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Rendered feedbacks/show.html.erb within layouts/application (36.2ms)
Completed 200 OK in 188ms (Views: 184.3ms | ActiveRecord: 1.8ms)

The wrong request

Started GET "/test2/feedbacks/7" for 127.0.0.1 at 2011-09-14 02:48:28 -0500
  Processing by FeedbacksController#show as HTML
  Parameters: {"username"=>"test2", "id"=>"7"}
  Feedback Load (0.1ms)  SELECT "feedbacks".* FROM "feedbacks" WHERE "feedbacks"."id" = ? LIMIT 1  [["id", "7"]]
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Rendered feedbacks/show.html.erb within layouts/application (37.6ms)
Completed 200 OK in 50ms (Views: 47.5ms | ActiveRecord: 1.2ms)
  • 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-25T16:27:52+00:00Added an answer on May 25, 2026 at 4:27 pm

    Your show action should look something like

    def show
      @user = User.find_by_username(params[:username])
    
      if @user == current_user
        ...
        render "show"
      else
        flash[:alert] = "Record doesn't exist"
        redirect_to root_path
      end
    end
    

    I took the liberty of adding in @Benoit’s suggestion.

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

Sidebar

Related Questions

This is my route: scope :username do resources :feedbacks end When I do rake
Suppose this is my URL route: (r'^test/?$','hello.life.views.test'), How do I make it so that
Trying to route: scope :shortcut do resources :text_elems end Using basic scaffold with form
I've started this question Named route with nested resources , and it lead me
Consider a string that looks like this: RR1 S5 C92 This a rural route
I have a route that I am calling through a RedirectToRoute like this: return
I have this in my routes.rb scope '/admin' do root :to => 'home#index' resources
When I just had resources :feedback in my routes.rb , I would use this
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,

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.