代码之家  ›  专栏  ›  技术社区  ›  Bryan Ward

查找rails中动作的HTML动词

  •  3
  • Bryan Ward  · 技术社区  · 15 年前

    有没有办法查找给定控制器操作的HTML?例如,我希望能够将GET与index相关联,将PUT与update相关联。我希望能够基于路由动态地执行此操作。

    {:action => :verb}

    3 回复  |  直到 15 年前
        1
  •  2
  •   Omar Qureshi    15 年前

    阅读rake routes任务,该任务将提供以下信息:

    例如:

    users GET    /users(.:format)     {:controller=>"users", :action=>"index"}
    

        2
  •  0
  •   Matt Briggs    15 年前

    :method :conditions 你可以传给谁 map.connect

      map.connect 'post/:id', :controller => 'posts', :action => 'create_comment',
                  :conditions => { :method => :get }
    
        3
  •  0
  •   just__matt    12 年前

    def all_routes
        @all_routes ||= Rails.application.routes.routes.map do |route|
              { alias: route.name,
                path: route.path.spec.to_s,
                controller: route.defaults[:controller],
                action: route.defaults[:action],
                verb: route.verb.source.to_s.delete('$'+'^')
              }
        end
    end