我对rails相对较新,无法找到答案。我添加了一个带有相应视图的控制器。当我去
根/ order_build /节目?构建= 1
我收到路由错误,说找不到路径,这是当我点击带有该地址的链接时。在我到达错误页面并手动刷新页面后,它可以工作。知道为什么会这样吗?
class OrderBuildController < ApplicationController
def show
@build= Build.find(request.GET["build"])
end
def order
end
def index
end
end
这是我的路由文件
ProjectD::Application.routes.draw do
get "order_build/show"
get "order_build/order"
get "order_build/index"
get "home/index"
#root :to => "home#index"
root :controller => 'home', :action => :index
resources :users, :user_sessions
match 'login' => 'user_sessions#new', :as => :login
match 'logout' => 'user_sessions#destroy', :as => :logout
resources :sessions
resources :providers
resources :build_prices
resources :products do
resources :product_images
end
resources :product_tags_products
resources :product_tags
resources :product_images
resources :orders
resources :order_statuses
resources :build_prices
resources :builds do
resources :build_prices
end
resources :build_statuses
resources :account_types
end
答案 0 :(得分:2)
您需要将路线与相应的控制器相关联
所以,而不是:
get "order_build/show"
你会这样做:
match "/order_build/show" => "order_build#show"
这样您就可以将/ order_build / show路由与order_build控制器上的show方法相关联。