我不明白如何在名称空间中生成资源,以及资源中的资源:有问题的子折叠.如何在rails控制器和视图中生成这样的路由:
namespace :admin do
namespace :catalogs do
namespace :parfume do
resource :brand do
resource :models do
我试图这样做:
rails g脚手架管理::Catalog
等等。
rails g脚手架管理::目录::To::Brand
但在路线上,我看到rails正在产生许多这样的路线:
namespace
首先,为什么我们需要命名控制器?
上的示例如下所示
namespace :admin do
resources :post, :comments
end
在本例中,我们有如下路径: GET /admin/post。它和获取/posts是一样的吗?或者GET /posts被保留为原始状态,而另一个GET /admin/posts被添加为额外的?
rails是否为名称空间创建了其他东西?
我对Rails相当陌生,在为我的rails项目构建本地化的过程中。我遵循了Rails i18n指南,并且能够使用本地化路径来访问站点的不同语言版本。
我的routes.rb如下所示:
scope "/:locale" do
# blah
end
namespace :admin do
# admin blah
end
但是,正如Rails指南中所建议的那样,由于我在应用程序控制器中使用了default_url_options,由URL生成的路径也将包含地区参数。当我创建指向我的管理根localhost:3000/admin?locale=en的链接时,我将得到一个错误
我正在编写Rails engine,但我不确定如何扩展我的配置/应用程序.rb
我想我必须以某种方式获取应用程序名称,有什么想法吗?
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails
我看到了这样一段用于路由的Rails代码:
namespace :my do
resource :auth_states, only: [] do
collection do
get 'signed_in'
end
end
resource :password, only: [:edit, :update]
# And all the actions a logged in user can perform under "my" namespace...
# ...
end
据推测,这个应用程序适
使用Rails 3中的路由,使用命名空间路由,如下例所示.
namespace :admin do
get 'dashboard' => 'dashboard#index'
end
...how我可以让'/admin‘路由到'dashboard#index’以及‘/admin/仪表板’吗?最好的方法是定义..。
get 'admin' => 'admin/dashboard#index'
在名称空间之外,还是有一种更优雅的方法来别名资源?
我使用Rails 3.2.2,我想为嵌套的资源生成一个正确的url_for URL。也就是说,我有:
# config/routes.rb
resources :articles do
resources :user_associations
end
# app/models/article.rb
class Article < ActiveRecord::Base
...
end
# app/models/articles/user_association.rb
class Articles::UserAssociation < ActiveRecord::Base
Rails 5.1.3
在rails中的路由文件中有一组命名空间的路由:
Rails.application.routes.draw do
get 'page/index'
namespace :admin do
resources :pages
resources :sections
end
get '*page', to: 'page#index'
root 'page#index'
# For details on the DSL available within this fi
我升级了rails 4.2.0和spree 3.0
一旦我运行了rspec,我就得到了以下错误,它显示了rspec ActionController::UrlGenerationError在rails 4.2.0中,我已经搜索了很多,但没有找到任何解决方案,请在下面的日志中找到:
Run options: include {:locations=>{"./spec/controllers/messages_controller_spec.rb"=>[10]}}
F
Failures:
1) MessagesController create with val
我尝试在多个菜单中设置相同的模型,一个作为可排序树,另一个作为常规crud。注册为crud的此实例嵌套在另一个模型中,因此..我有过
ActiveAdmin.register Parent do
end
ActiveAdmin.register Child do
belongs to :parent
end
ActiveAdmin.register Child, as: 'Child1' do
menu :parent => "Parent1"
end
ActiveAdmin.register Child, as: 'Child2
我正在努力了解更多关于铁轨路线的知识。
成员与集合
# Example resource route with options:
resources :products do
member do
get 'short'
post 'toggle'
end
collection do
get 'sold'
end
end
名称空间和作用域
# Example resource route within a na
我想知道是否有一种方法可以在Rails中使用“足智多谋的路由”,让所有路由指向一个controller#action。我想让React Router来处理链接。
我查看了并找到了这个
我当前的routes.rb文件(这是实现此目的的最佳方式吗?):
Rails.application.routes.draw do
root to: "home#index"
get 'games', to: 'home#index'
get 'games/new', to: 'home#index'
get '
我需要放一个新的家在新的地区,但我有一个错误:发现多个类型匹配控制器命名为‘家’。如果为此请求提供服务的路由('{ controller }/{action}/{id}')未指定命名空间来搜索与该请求匹配的控制器,则可能会发生这种情况。如果是这种情况,请通过调用接受“namespaces”参数的“MapRoute”方法的重载来注册此路由。我的新领域
Areas/Administrativo/Controllers/HomeController
区域/管理/视图/主页
我的AdministrativoAreaRegistration
public override voi
namespace :admin do
resources :posts do
collection do
get 'whatever'
end
end
end
我原以为这会生成'whatever_admin_posts_path‘助手方法,但它没有。
我的密码有问题吗?还是rails中的一个bug?
在我正在做的一个Rails3.2应用程序中,我想创建一些特定于移动设备的视图(和操作处理)。所以我创建了一个名为mobile的命名空间。
namespace :mobile do
resources :sessions
resources :areas
end
例如,如果用户使用手机进入登录页面,我希望使用我为该名称空间创建的控制器和视图。
所以现在我有两种不同的登录方式:
new_mobile_session GET /mobile/sessions/new(.:format) mobile/sessions#new
和
new_session G