Curious about Community Engine Routing

6 views
Skip to first unread message

Audrey A Lee

unread,
Nov 20, 2009, 4:21:15 PM11/20/09
to CommunityEngine
Hello,

I'm curious about how routing works in CE.

I see 2 ways to answer the question.

First, I could make interesting changes to vendor/plugins/
community_engine/config/desert_routes.rb
and study the results.

Second, I could just ask questions in this group.

I guess I'll do both.

Here is my 1st question.

Given that I am logged in as bob22
And I go to http://localhost:3000/abc123xyz
Then I get redirected to http://localhost:3000/bob22

Where do I find the ruby-code which causes the behavior?

--Audrey

Levi Rosol

unread,
Nov 20, 2009, 4:35:34 PM11/20/09
to communi...@googlegroups.com
I'm also curious about this.

--
Levi Rosol
Twitter: @LeviRosol




--

You received this message because you are subscribed to the Google Groups "CommunityEngine" group.
To post to this group, send email to communi...@googlegroups.com.
To unsubscribe from this group, send email to communityengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/communityengine?hl=.



Audrey A Lee

unread,
Nov 20, 2009, 4:42:42 PM11/20/09
to CommunityEngine
I got a big clue by just looking at the console log.

Given that I am logged in as bob22
And I go to http://localhost:3000/abc123xyz
Then I get redirected to http://localhost:3000/bob22
Because of ruby-code in UsersController#show

I'll drop a debugger in the .show() method and see what I can learn.

--Audrey


On Nov 20, 1:21 pm, Audrey A Lee <audrey.lee.is...@gmail.com> wrote:
> Hello,
>
> I'm curious about how routing works in CE.
>
> I see 2 ways to answer the question.
>
> First, I could make interesting changes to vendor/plugins/
> community_engine/config/desert_routes.rb
> and study the results.
>
> Second, I could just ask questions in this group.
>
> I guess I'll do both.
>
> Here is my 1st question.
>
> Given that I am logged in as bob22
> And I go tohttp://localhost:3000/abc123xyz
> Then I get redirected tohttp://localhost:3000/bob22

Bruno Bornsztein

unread,
Nov 20, 2009, 6:38:39 PM11/20/09
to communi...@googlegroups.com
The method you're interested in is BaseController#find_user, which is
called from a before_filter in UsersController. When a user can't be
found, it redirects to the login page (and if you're already logged
in, that sends you to your profile page).

On Nov 20, 2009, at 3:42 PM, Audrey A Lee <audrey.l...@gmail.com>
wrote:

Audrey A Lee

unread,
Nov 20, 2009, 6:47:46 PM11/20/09
to CommunityEngine
ok,

I figured out enough to do what I want to do.

I made a very tiny change to desert_routes.rb:

resources :users, :member_path => '/usr/:id', :nested_member_path => '/
usr/:user_id', :member => {

Then I added 1 line to routes.rb:

map.connect '/*pkey', :controller => 'posts', :action =>
'pkey_show', :conditions => { :method => :get }

After coding up .pkey_show() and adding a template for it,
I am happy.

Now, if I go to this URL:

http://localhost:3000/abc123xyz

I see a post (or not) rather than a user.

--Audrey

Audrey A Lee

unread,
Nov 20, 2009, 7:05:01 PM11/20/09
to CommunityEngine
Well,

It looks like desert_routes.rb wants to live under vendor/

When I copy it to RR/config/
it gets ignored.

I don't like editing files under vendor but I'm happy enough.

--Audrey

Bruno Bornsztein

unread,
Nov 21, 2009, 9:03:41 AM11/21/09
to communi...@googlegroups.com
It looks like desert_routes.rb wants to live under vendor/

To create routes for your Rails app, you need to put them in config/routes.rb (like any normal app).  

> I made a very tiny change to desert_routes.rb:
>
> resources :users, :member_path => '/usr/:id', :nested_member_path => '/
> usr/:user_id', :member => {
>
> Then I added 1 line to routes.rb:
>
>   map.connect '/*pkey', :controller => 'posts', :action =>
> 'pkey_show', :conditions => { :method => :get }
>
> After coding up .pkey_show() and adding a template for it,
> I am happy.
>
> Now, if I go to this URL:
>
>  http://localhost:3000/abc123xyz
>
> I see a post (or not) rather than a user.

Just for the record, in case other people come along and see this; this is not a recommended approach to customizing a CE app. You're going to encounter lots of errors due to the fact that you're routing /params to posts/show instead of users/show.

If your goal is to have blog posts routed to /params (though I don't recommend it), there are better ways to do it.

Thanks,
Bruno

 

Audrey A Lee

unread,
Nov 21, 2009, 3:34:10 PM11/21/09
to CommunityEngine
Bruno,

Thanks for the info.

If you get a few free minutes,
please post a few sentences or some routing code which
routes /params to the posts/show method.

This might a bit of a task though; I'm not sure.

It looks like many hours were used to construct desert_routes.rb

--Audrey


On Nov 21, 6:03 am, Bruno Bornsztein <bruno.bornszt...@gmail.com>
wrote:

Jim Ruther Nill

unread,
Nov 22, 2009, 2:05:29 AM11/22/09
to communi...@googlegroups.com
as Bruno said, try overriding the BaseController#find_user action.  If you really want posts as your priority when the url is http://url.com/post_title, try this

def find_user
    if @post = Post.find_by_name(params[:user_id] || params[:id])
      redirect_to @post and return
    elsif @user = User.active.find(params[:user_id] || params[:id])
      ... default BaseController#find_user implementation
    end
  end

disclaimer: i haven't tried this code yet. just a quick implementation out of my head

But as Bruno said (again), this is not recommended.

Reply all
Reply to author
Forward
0 new messages