Hi,

I have this route that let me build custom url for users like
/thisismyname, and it works fine. But when I look at the log there is
something I don't like...

When I hit /gregory this is what is happenning:
1. Going to public_profile#public # Good
2. hitting /assets and trying to find a user with asset token # Not good

I thought my constraints would avoid this but it doesn't seem like it...

class PublicProfileConstraint
def self.matches?(request)
['assets', 'admin'].include?(request.session[:token])
end
end

get "/:token" => "profiles#public", :as => :public_profile,
:constraints => PublicProfileConstraint


Here is the log:

Started GET "/gregory" for 127.0.0.1 at 2012-03-05 12:44:43 -0800
Processing by ProfilesController#public as HTML
Parameters: {"token"=>"gregory"}
Lawyer Load (0.2ms) SELECT "users".* FROM "lawyers" WHERE
"users"."id" = ? LIMIT 1 [["id", 1]]
Lawyer Load (0.3ms) SELECT "users".* FROM "lawyers" WHERE
"users"."token" = 'gregorymarcilhacy' LIMIT 1
Rendered profiles/_modal.haml (0.1ms)
....
Rendered profiles/show.haml within layouts/application (154.7ms)
Completed 200 OK in 431ms (Views: 174.0ms | ActiveRecord: 5.5ms)

... Redering js files ...

# I DONT WANT THIS
Started GET "/assets/" for 127.0.0.1 at 2012-03-05 12:44:45 -0800
Served asset - 404 Not Found (10ms)
Processing by ProfilesController#public as */*
Parameters: {"token"=>"assets"}
Lawyer Load (0.2ms) SELECT "lawyers".* FROM "lawyers" WHERE
"users"."id" = ? LIMIT 1 [["id", 1]]
Lawyer Load (0.3ms) SELECT "lawyers".* FROM "lawyers" WHERE
"users"."token" = 'assets' LIMIT 1
Redirected to http://localhost:3000/
Completed 302 Found in 312ms

... Rendering images ...

# AND I DONT WANT THIS
Started GET "/" for 127.0.0.1 at 2012-03-05 12:44:45 -0800
Processing by LandingController#landing as */*
Lawyer Load (0.3ms) SELECT "lawyers".* FROM "users" WHERE
"users"."id" = ? LIMIT 1 [["id", 1]]
Rendered landing/landing.haml within layouts/landing (0.8ms)
Completed 200 OK in 288ms (Views: 23.5ms | ActiveRecord: 2.2ms)

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Tim Shaffer at Mar 6, 2012 at 1:08 pm
    Your constraint is slightly wrong.

    Unless you are settings "request.session[:token]" somewhere else in your
    code, chances are it's going to be nil. What you most likely want to check
    for is "request.params[:token]" which will match the token in the URL.

    You also have it backwards. The constraint would currently only ALLOW
    assets and admin. You need to negate that statement.

    Fix those 2 issues and you should be in business.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/tekiOBqzguYJ.
    To post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 5, '12 at 8:48p
activeMar 6, '12 at 1:08p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Greg Ma: 1 post Tim Shaffer: 1 post

People

Translate

site design / logo © 2023 Grokbase