标签: custom-routes

rails奇异资源还是复数吗?

我有一个搜索路线,我想做出单数,但当我指定一个单一的路线,它仍然制作多个控制器路线,这是它应该如何?

resource :search
Run Code Online (Sandbox Code Playgroud)

给我

 search POST        /search(.:format)        {:action=>"create", :controller=>"searches"}
 new_search  GET    /search/new(.:format)    {:action=>"new", :controller=>"searches"}
 edit_search GET    /search/edit(.:format)   {:action=>"edit", :controller=>"searches"}
             GET    /search(.:format)        {:action=>"show", :controller=>"searches"}
             PUT    /search(.:format)        {:action=>"update", :controller=>"searches"}
             DELETE /search(.:format)        {:action=>"destroy", :controller=>"searches"}
Run Code Online (Sandbox Code Playgroud)

多个控制器"搜索"

我只有一条路线......创建一个搜索:

所以我做了: match "search" => "search#create"

如果我仍然想让控制器复数,我只是想知道未来?Rails 3.0.9

routes ruby-on-rails singular custom-routes ruby-on-rails-3

37
推荐指数
4
解决办法
2万
查看次数

Rails3路由 - 将参数传递给成员路由

我想将一个额外的参数传递给资源的成员路由

就像是:

resources :events do
  member do
    get 'register/:participant_type_id'
  end
end
Run Code Online (Sandbox Code Playgroud)

我只能使用静态匹配语句来完成它

环顾互联网,我发现在Rails 3.0.2中这可能是可行的.我使用的是3.0.1而且它不是.

难道我做错了什么?还是真的不可能?

谢谢

routes ruby-on-rails custom-routes ruby-on-rails-3

28
推荐指数
2
解决办法
2万
查看次数

为什么在Rails中没有自定义路由的路径名

在我的rails应用程序中跟随routes.rb

resources :users
Run Code Online (Sandbox Code Playgroud)

导致'rake routes'的输出结果

 users        GET    /users(.:format)                 users#index
              POST   /users(.:format)                 users#create
 new_user     GET    /users/new(.:format)             users#new
 edit_user    GET    /users/:id/edit(.:format)        users#edit
 user         GET    /users/:id(.:format)             users#show
              PUT    /users/:id(.:format)             users#update
              DELETE /users/:id(.:format)             users#destroy
Run Code Online (Sandbox Code Playgroud)

&follow在routes.rb中(对于我的自定义控制器'home')

match  '/new_user'        =>          'home#new_user', via: [:get]
match  '/users/:id/edit'  =>          'home#edit_user', via: [:get]
match  '/users/:id'       =>          'home#show_user', via: [:get]
match  '/users/:id'       =>          'home#create_user', via: [:post]
Run Code Online (Sandbox Code Playgroud)

导致'rake routes'的输出结果

GET    /new_user(.:format)                home#new_user
GET    /users/:id/edit(.:format)          home#edit_user
GET    /users/:id(.:format)               home#show_user
POST   /users/:id(.:format)               home#create_user
Run Code Online (Sandbox Code Playgroud)

为什么第二种情况没有路径名?比如第一种情况('new_user','edit_user')

有没有办法让第二种情况的路径名?因为我想在我的视图中使用这些路径名称

routes ruby-on-rails custom-routes ruby-on-rails-3

14
推荐指数
1
解决办法
1万
查看次数

要映射到rails 4中的自定义路径的资源路由

我有一条路线:

resources :products
Run Code Online (Sandbox Code Playgroud)

现在我已经将所有代码都安装到位,但只需要更改路径 /products/:action to /items/:action

我已经浏览了rails docs但是无法解决这个问题.它看起来很基本,应该很容易,但我不能把手指放在上面.

我使用的网址是:http://guides.rubyonrails.org/routing.html#path-and-url-helpers

custom-routes ruby-on-rails-4

11
推荐指数
2
解决办法
7426
查看次数

MVC自定义路由中的多个级别

我正在尝试建立自己的小cms.我创建了一个抽象的pageBase类,它由Static,Reviews,Articles,News继承.每个都有自己的控制器方法.

我的问题是我需要允许管理员定义自己的自定义路径级别.例如news\local\mynewdogArticles\events\conventions\mycon.所以我想要一种传递字符串数组并设置自定义路由的方法.

c# asp.net-mvc url-routing asp.net-mvc-routing custom-routes

7
推荐指数
1
解决办法
3419
查看次数

rails路由别名

我有一个模型Spaces,它有不同类型的地方......如酒吧,餐馆等.它有相同的列,相同,模型,控制器等没有花哨的STI,我只有一个字段叫Space_type我想要确定别名路线.

而不是 domain.com/spaces/12345/bars/12345/clubs/12345

目前我有:

  resources :spaces do
    collection do
      get :update_availables
      get :update_search
      get :autocomplete
    end
    member do
      post :publish
      post :scrape
    end
    resources :photos do
      collection do
        put :sort
      end
    end

    resources :reviews
  end
Run Code Online (Sandbox Code Playgroud)

另外,有没有办法可以做到这一点,以便我随时使用space_url它可以找出使用哪一个?

routes ruby-on-rails url-routing custom-routes ruby-on-rails-3

6
推荐指数
2
解决办法
8043
查看次数

自定义收集路由的polymorphic_path

我有以下路线定义:

resources :documents do
  collection do
    post :filter
  end
end
Run Code Online (Sandbox Code Playgroud)

以及以下模型结构:

class Document < ActiveRecord::Base
  belongs_to :documentable, :polymorphic => true
end

class User < ActiveRecord::Base
  has_many :documents, :as => :documentable
end
Run Code Online (Sandbox Code Playgroud)

和控制器结构:

class DocumentsController < ApplicationController
  def index
    # not important
  end

  def filter
    # not important
  end
end
Run Code Online (Sandbox Code Playgroud)

我可以轻松地在一个视图中说:

polymorphic_path([@user, Document])
Run Code Online (Sandbox Code Playgroud)

获取路径/ users/1/documents,但我希望能够说:

filter_polymorphic_path([@user, Document])
Run Code Online (Sandbox Code Playgroud)

不幸的是,获取路径/ users/1/documents/filter,这不起作用.

对于我的每个可记录模型,任何人都知道如何在不添加以下内容的情况下将其删除:

resources :users do
  resources :documents do
    collection do
      post :filter
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

routes ruby-on-rails polymorphic-associations custom-routes ruby-on-rails-3

6
推荐指数
1
解决办法
6110
查看次数

在Rails 3中创建SEO友好URL

我目前的网址如下:

things?category_id=6&country_id=17
Run Code Online (Sandbox Code Playgroud)

我希望网址看起来像这样:

/printer_cartridges/united_kingdom
Run Code Online (Sandbox Code Playgroud)

在Rails 3中是否有一种方法,没有对路由器中的所有类别和国家进行硬编码以获得我想要的URL,可能使用find_by_name或类似的?解决这个问题的最佳方法是什么?

routing routes ruby-on-rails custom-routes

5
推荐指数
1
解决办法
3328
查看次数

如何在rails 3中定义自己的路由助手?

我使用polimorphic_path并且它有些马车.此方法需要一些未定义的路由助手.我如何定义(像常规方法)自己的路由助手将使用像"model_name_path,model_name_url等"?

routes ruby-on-rails custom-routes

5
推荐指数
1
解决办法
1904
查看次数

Slim3可选参数,带控制器方法作为回调

我有路线:

$app->get('/admin/login/{status}', 'App\Controller\Admin\AdminController:loginAction')
Run Code Online (Sandbox Code Playgroud)

如何使{status}参数可选?

slim custom-routes slim-3

5
推荐指数
1
解决办法
3289
查看次数