Monday, March 5, 2012

[Rails] Twitter like route

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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate