English 中文(简体)
铁路3 - 主计长/意见分局 统一
原标题:Rails 3 - Controller/View Subdirectories Routing

我有一些控制人员分散到以下次级单位:

app/dept1/user_controller/action

在控制器中配置这一配置:

class Dept1::UserController < ApplicationController
end

在铁路2号,我都需要这样做,申请能够自动进行公正的罚款。

但是,在铁路3中,我似乎需要做一些路线组合。 I ve Trial using namespaces:

  namespace :dept1 do
    resources :user
  end

This page pulls up fine:

app/dept1/user_controller/index

但是, app/dept/用户-控制者/报告也发现了这一错误:

 "ActionController::RoutingError (No route matches [POST] "/dept1/user/report")"

我还需要做些什么?

最新资料:

当我把这一点放在我的道路上时,它努力:

namespace :dept1 do
  resources :user do
    collection do
      get :report
      post :report
    end
  end
end

如果没有每项行动硬性规定,我是否能够做到这一点?

MORE UPDATES:

在此,我为确定工作路线做了些什么。 必须做到:

match  :controller(/:action(/:id)) , :controller => /dept1/[^/]+/
match  :controller(/:action(/:id(.:format))) 
问题回答

这是强迫你设计URL RESTful的一个特点。 但是,如果你真的想要铁路2行,则会发现混凝土/铁丝带的最后一块块:

# This is a legacy wild controller route that s not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match  :controller(/:action(/:id(.:format))) 

该评论说,它使GET能够进入,实际上,它使得所有吉大港山区都能够进入。

关于腾出的资源,我猜测你需要在<条码>下确定上述规则:dept1。

但是,我仍然建议你使用铁路3,只暴露灵感。





相关问题
Remove ActiveRecord in Rails 3

Now that Rails 3 beta is out, I thought I d have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB ...

When will you upgrade your app to Rails 3? [closed]

Now that the Rails 3 beta is here, let s take a little straw poll. Please tell us briefly what your application does and when you will upgrade it to Rails 3. Or, if you re not planning on upgrading ...

Bundler isn t loading gems

I have been having a problem with using Bundler and being able to access my gems without having to require them somewhere, as config.gem used to do that for me (as far as I know). In my Rails 3 app, I ...

bypass attr_accessible/protected in rails

I have a model that, when it instantiates an object, also creates another object with the same user id. class Foo > ActiveRecord::Base after_create: create_bar private def create_bar Bar....

concat two fields activerecord

I m so used to oracle where you can simply concat(field1, , field2) but if I m using activerecord to find the field1 and field2, and I need a space in between, how do I accomplish this? Cheers ...

热门标签