0

我对 Rails 比较陌生,找不到答案。我添加了一个带有相应视图的控制器。当我去

根/order_build/show?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
4

1 回答 1

2

您需要将您的路线与相应的控制器相关联

所以,而不是:

get "order_build/show"

你会这样做:

match "/order_build/show" => "order_build#show"

这样,您将 /order_build/show 路由与 order_build 控制器上的 show 方法相关联。

于 2013-04-03T17:44:59.767 回答