代码之家  ›  专栏  ›  技术社区  ›  Madhusudhan

未知操作没有操作响应显示

  •  3
  • Madhusudhan  · 技术社区  · 16 年前

    我使用脚手架生成了一个模型用户

    
    script/generate scaffold user username:string crypted_password:string email:string active:boolean perishable_token:string persistance_token:string

    然后我在UsersController中添加了一个方法

    
    def test
    end
    

    然后创建了一个视图文件test.html.erb,我正在打印“Hello”

    所以现在我想进入localhost:3000/users/test

    
    Unknown action
    No action responded to show. Actions:...
    

    在我的路线上。我有

    
    map.resources :users
    

    当我看到开发日志时,它将参数“test”作为“id”,其中作为一个操作。

    1 回复  |  直到 16 年前
        1
  •  4
  •   lwe    16 年前

    您需要定义附加操作,请参阅 http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

    map.resources :users, :collection => { :test => :get }
    

    检查所有路由的有用工具是 rake routes