【问题标题】:Ruby on Rails routes trouble for deploymentRuby on Rails 路由部署问题
【发布时间】:2018-10-10 16:35:06
【问题描述】:

我尝试在 Sinatra 中运行这个程序,但 Heroku 不允许我使用它。它部署成功,但无法在 Heroku 中运行,所以我决定在 rails 中启动这个程序。

Rails.application.routes.draw do
  root 'pages#index'
  # get 'cookies#index'
  # get 'cakes#index'
  # get 'cookies#index'
  # get 'crumbcakes#index'
  # get 'cupcakes#index'
  # get 'events#index'
  # get 'muffins#index'
  # get 'pastries#index'

  resources :index
  # resources :about
  # resources :cakes
  # resources :cookies
  # resources :crumbcakes
  # resources :cupcakes
  # resources :events
  # resources :muffins
  # resources :pastries
end

我将它作为 Rails 中的路由,但我将它们注释掉,因为它只适用于索引页面。我对每个控制器和视图都有索引。只有一个索引。我不知道我是否没有以正确的格式放置路线。如果你能帮助我,请告诉我谢谢!

【问题讨论】:

  • 这个问题没有意义——你知道 sinatra 是一个完全不同的框架吗?

标签: ruby-on-rails ruby routes


【解决方案1】:

为了让各种控制器的索引操作只有路由,您需要指定如下:

resources :controller_name, only: %i(index)
  or
resources :controller_name, only: [:index]

【讨论】:

  • 控制器是 muffins_controlller.rb
  • 那么你需要指定类似的资源:松饼,仅:%i(index)
  • 它的resources :resource_name(plural)。推断出控制器名称。
【解决方案2】:

应该是

resources :cookies, only: [:index]
resources :cakes, only: [:index]
resources :muffins, only: [:index]
 ..... 

查看官方指南以获得清晰的概念guides.rubyonrails.org/routing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多