문제

I have a padrino project.

I've created a sub app called "users".

I also have a model called user and a controller called users to handle the routing.

Users.controllers :users do

The issue with that is that the urls being produced and being responded to are

app.com/users/users/index etc

unless I go to each action and map it

get :index, :map => '/' do

Is there a better way of doing this?

I don't really want to put the actions in the app.rb for the app.. even though that works great. I like having the separation.

Is there anything like

Users.controllers :users do
    map '/'
end

Is there a naming convention that I can follow to create a default controller that would response to my apps root url?

I'd like to keep it in the users controller so that I can use the users_index etc

Gems included by the bundle:

activemodel (3.2.1)
activerecord (3.2.1)
activesupport (3.2.1)
arel (3.0.0)
bcrypt-ruby (3.0.1)
builder (3.0.0)
bundler (1.0.21)
haml (3.1.4)
http_router (0.10.2)
i18n (0.6.0)
mail (2.3.0)
mime-types (1.17.2)
multi_json (1.0.4)
padrino (0.10.6.c)
padrino-admin (0.10.6.c)
padrino-cache (0.10.6.c)
padrino-core (0.10.6.c)
padrino-gen (0.10.6.c)
padrino-helpers (0.10.6.c)
padrino-mailer (0.10.6.c)
polyglot (0.3.3)
rack (1.4.1)
rack-protection (1.2.0)
rack-test (0.6.1)
rake (0.9.2.2)
sass (3.1.13)
shoulda (2.11.3)
sinatra (1.3.2)
sinatra-flash (0.3.0)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.31)
url_mount (0.2.1)

If I have to map the path for each action in the controller when my app name matches my controller name, that's fine. I was just wondering if there was a way to set the base or root path for all my actions via the controller.

Thanks

도움이 되었습니까?

해결책

#padrino-core-0.10.6.c/lib/padrino-core/application/routing.rb

#around line 655
#method parse_route

#right after unless controller.empty? i added the following which works in my case

   if controller.last.downcase == app_name.downcase and map.blank?
    controller = controller.slice(0, -2) unless controller.length == 1
    controller_path = controller.join("/")
    path.gsub!(%r{^\(/\)|/\?}, "")
    map = File.join(controller_path, path)
end

So now if I have an application called Users and a controller called Users to handle the routes, I can just say /users or /users/new etc instead of /users/users/new.

Again, I'm very new to this, so I have no idea if this is the best way to handle this. I could have just set the map manually in each route, but that would be very annoying.

I'm hoping that DAddYE can weight in on this and provide a better recommendation.

다른 팁

You can use directly:

get "/" do
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top