【问题标题】:How write only once path_names on routes and make available for all of routes in Rails 4.1?如何在路线上只写一次 path_names 并使其可用于 Rails 4.1 中的所有路线?
【发布时间】:2014-12-31 06:41:39
【问题描述】:

我只想将我的 path_names 翻译一次,并使其可用于routes.rb 中的所有路线。

这是我现在的routes.rb

PATH_NAMES = { new: 'novo', edit: 'editar', show: 'ver' }

Rails.application.routes.draw do

  devise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks',
                                    registrations: 'registrations' }

  resources :movements, :path => 'fluxo-de-caixa', path_names: PATH_NAMES
  resources :movement_categories, :path => '/fluxo-de-caixa/categorias', path_names: PATH_NAMES
  resources :installments, :path => 'parcelas', path_names: PATH_NAMES
  resources :contracts, :path => 'contratos', path_names: PATH_NAMES
  resources :accounts, :path => 'contas', path_names: PATH_NAMES
  resources :events, :path => 'eventos', path_names: PATH_NAMES
  resources :users, :path => 'usuarios', path_names: PATH_NAMES
  resources :spectator, :path => 'espectadores', path_names: PATH_NAMES

  devise_scope :user do
    get '/cadastrar' => 'devise/registrations#new'
    get '/entrar' => 'devise/sessions#new'
    get '/editar' => 'devise/registrations#edit'
    delete '/sair' => 'devise/sessions#destroy'
  end

  root 'home#index'
end

希望你能帮帮我!!

我的问候! ;D

【问题讨论】:

    标签: ruby ruby-on-rails-4 routes pathname


    【解决方案1】:

    使用scope:

    scope(path_names: { new: 'novo', edit: 'editar', show: 'ver' }) do
      resources :movements, :path => 'fluxo-de-caixa'
      resources :movement_categories, :path => '/fluxo-de-caixa/categorias'
      resources :installments, :path => 'parcelas'
      resources :contracts, :path => 'contratos'
      resources :accounts, :path => 'contas'
      resources :events, :path => 'eventos'
      resources :users, :path => 'usuarios'
      resources :spectator, :path => 'espectadores'
    end
    

    【讨论】:

      猜你喜欢
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      相关资源
      最近更新 更多