我的routes.rb文件如下所示: resources :contents, only: [:show]
get 'contents/by_hardware', to: 'contents#show_by_hardware' 使用此设置时,我无法访问contents/by_hardware路由。 但是,如果我以不同的顺序设置我的routes.rb文件,一切都会正常工作。 get 'contents/by_hardware', to: 'contents#show_by_hardware'
resources :cont
首先,我尝试访问routes.rb文件中的会话变量,并放入一个简单的if语句。如果用户已登录,请转到entry#index,否则请转到landing#index。但是,routes.rb似乎没有访问会话变量的权限。我设置了session:user_id,可以用它来验证登录状态。最好是在routes.rb中将已注销页面设置为主页,然后在该控制器中重定向(如果用户已登录),或者有没有更好的方法,但我不知道?
下面是我在控制器中为注销用户主页所做的操作。
def index
if User.find_by_id(session[:user_id])
redirect_t
因此,在我们的Rails4.2应用程序中,有一个routes.rb,它要求在alchemy_cms /routes.rb中最后挂载它的路由。
SampleApp::Application.routes.draw do
#other routes for the rails app here
# :
# :
mount Alchemy::Engine => '/'
end
我们得到像"/somehacker/routingurl“这样的路由,然后将其交给Alchemy::Engine来处理,从而导致默认的500错误。如果我想做一个自定义的404错误,
可能是一些琐碎的事情,但我想知道根关键字及其控制器操作应该放在routes.rb文件中的哪里。
Rails.application.routes.draw do
get 'welcome/index'
root 'welcome#index'
end
我看了几个教程,其中大多数似乎都在底部。这有什么原因吗?
我正在使用w/ working 3应用程序,我希望根据子域将路由划分为不同的文件。现在,我的routes.rb文件中有这样的内容:
Skateparks::Application.routes.draw do
constraints(:subdomain => 'api') do
load 'routes/api.rb'
end
end
在我的路线/api.rb文件中我有:
resources :skateparks
但是,这似乎不起作用,因为如果我运行rake routes,就会得到
undefined method `resources
对于Rails引擎的应用程序控制器中的before_action,当用户从引擎请求动作时,before_action是在加载引擎的routes.rb和models之前执行的(或一些允许我们查找执行顺序的过程/工具)。调试似乎跳过了routes.rb和模型定义)?
class ApplicationController < ApplicationController
before_action :setup_some_variable
..........
end
setup_some_variable的目的是设置将用于引擎中的routes.rb和models中的变量。
我在routes.rb中有两个routes.rb方法
get 'orders/:id-:phone', to: 'orders#show', as: :order_phone
get ':id/:url', to: 'point_pages#show', as: :page_url
因此,对于Order模型,我需要像:domain.com/orders/1-88888888888 (88888888888 -是order.user的电话号码)和PointPage模型- domain.com/1/some_long_point_pa
我试图在安装后编写我的第一个程序,但我得到了如下错误:
Routing Error
No route matches [GET] "/firstapp"
我试图更改我的config/routes.rb文件,但什么也没有更改。这是我的config/routes.rb
Firstapp::Application.routes.draw do
resources :apptables
# The priority is based upon order of creation:
# first created -> highest priority.
# c
我用的是rails 3+设计。当用户注册时出现错误。该应用程序将重定向到:
http://localhost:3000/users
显示错误消息,但在日志中我看到以下内容:
Started POST "/users" for 127.0.0.1 at Mon Jul 11 20:22:19 -0700 2011
Processing by RegistrationsController#create as HTML
Parameters: {"commit"=>"Create my account", "fb_access_
假设Rails应用程序绘制了以下路由(即rake routes将显示的路由):
Verb URI Pattern Controller#Action
GET / one#show
GET / two#show
GET / three#show
当请求根路径(即/)时,这些路由的匹配顺序是什么?是什么因素决定了哪条路线是第一个匹配的?
背景:我面临一个Rails应用程序(讨论),我正在为它编写一个插件。Rails应用程序通过root to:在其routes.rb文件中设置一系列根路由。我的插件试图提供自己的根路径,
我有问题让我的帮助器方法名称正常工作,任何建议都会很好:
#config/routes.rb
resources :junkie, only: [:show, :index, :destroy], as: :junkie do
get :merge, on: :collection
end
所以我遇到了一些问题,因为我发现junkies的单数形式是junky,但当我进行此更改并查看路由时,它会将#merge助手更改为:
merge_junkie_index GET /junkies/merge(.:format) junkies#merge
有没有办法把它改
我只是在学习Rails,并构建了一个非常简单的应用程序,将信息存储到rake生成的db中。我试图给控制器添加一个新的动作,但是我不能触发它。有一个before_action被触发,这是不应该的。
class GamesController < ApplicationController
before_action :set_entry, only: %i[ show edit update destroy ]
before_action :authenticate_user!
def index
end
def analyse
#The function
当尝试访问http://localhost:3000/admin下的Active Admin仪表板时,我会被重定向到http://localhost:3000/users/sign_in。但是,我的路径显示了/admin路径。
admin_root_path GET /admin(.:format) admin/dashboard#index
admin_dashboard_path GET /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_users_path PO
我使用了脚手架,我想在routes.rb的资源中添加一个新的路由。
但是我想发送没有id参数的链接。
我想像访问index2.html.erb的fleamarkets_path那样访问index.html.erb。
routes.rb
resources :fleamarkets do
member do
get :index
end
end
默认rake路由
fleamarkets GET /fleamarkets(.:format) fleamarkets#index
rake路由
index2_fleamarket GET /fleama