无法将新页面/路由添加到Rails服务器

时间:2019-07-19 22:36:28

标签: ruby-on-rails

========= 编辑:删除和替换routes.rb解决了我的问题!!!

=====

我正在努力克服网站编码中的这种驼峰。我正在遵循不同的教程和指南,但是没有任何操作可以在我的网站上添加新页面,而且我找不到方法。

当我执行“铁路路线”时,没有新路线出现。服务器上的路由数量是否受到某种限制?

我开始转到页面控制器,并添加了“默认服务”和“结束”:

页面控制器

  def home
  end

  def about
  end

  def offerings
  end

  def public_speaking
  end

  def serve
  end   

end 

Routes.rb

然后在Routes.rb中,我尝试使用与以前相同的过程。我尝试了2种不同的方式来生成“服务”路线,但均无济于事:

  root to: "pages#home"

  get 'home/public_speaking'

  get 'serve', to: 'pages#serve'

  get "pages/:serve", to: "pages#serve"

  get 'home/serve'

  get 'public_speaking', to: 'pages#public_speaking'



    devise_for :users, controllers: { registrations: 'users/registrations' }
    resources :users do 
        resource :profile
    end 

  get 'about', to: 'pages#about'

  resources :contacts, only: [:create]

  get 'contact-us', to: 'contacts#new', as: 'new_contact'

  get 'public_speaking', to: 'pages#public_speaking'


end 

查看文件

我还在views文件夹中创建了一个名称相同的文件“ serve.html.erb”。

我做铁路路线时会显示什么

当我运行“铁路路线”时:

ubuntu@ip-172-31-91-225:~/environment/saasapp$ rails routes
                  Prefix Verb   URI Pattern                            Controller#Action
              pages_home GET    /pages/home(.:format)                  pages#home
             pages_about GET    /pages/about(.:format)                 pages#about
         pages_offerings GET    /pages/offerings(.:format)             pages#offerings
   pages_public_speaking GET    /pages/public_speaking(.:format)       pages#public_speaking
                    root GET    /                                      pages#home
        new_user_session GET    /users/sign_in(.:format)               devise/sessions#new
            user_session POST   /users/sign_in(.:format)               devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)              devise/sessions#destroy
           user_password POST   /users/password(.:format)              devise/passwords#create
       new_user_password GET    /users/password/new(.:format)          devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)         devise/passwords#edit
                         PATCH  /users/password(.:format)              devise/passwords#update
                         PUT    /users/password(.:format)              devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                users/registrations#cancel
       user_registration POST   /users(.:format)                       users/registrations#create
   new_user_registration GET    /users/sign_up(.:format)               users/registrations#new
  edit_user_registration GET    /users/edit(.:format)                  users/registrations#edit
                         PATCH  /users(.:format)                       users/registrations#update
                         PUT    /users(.:format)                       users/registrations#update
                         DELETE /users(.:format)                       users/registrations#destroy
            user_profile POST   /users/:user_id/profile(.:format)      profiles#create
        new_user_profile GET    /users/:user_id/profile/new(.:format)  profiles#new
       edit_user_profile GET    /users/:user_id/profile/edit(.:format) profiles#edit
                         GET    /users/:user_id/profile(.:format)      profiles#show
                         PATCH  /users/:user_id/profile(.:format)      profiles#update
                         PUT    /users/:user_id/profile(.:format)      profiles#update
                         DELETE /users/:user_id/profile(.:format)      profiles#destroy
                   users GET    /users(.:format)                       users#index
                         POST   /users(.:format)                       users#create
                new_user GET    /users/new(.:format)                   users#new
               edit_user GET    /users/:id/edit(.:format)              users#edit
                    user GET    /users/:id(.:format)                   users#show
                         PATCH  /users/:id(.:format)                   users#update
                         PUT    /users/:id(.:format)                   users#update
                         DELETE /users/:id(.:format)                   users#destroy
                   about GET    /about(.:format)                       pages#about
                contacts POST   /contacts(.:format)                    contacts#create
             new_contact GET    /contact-us(.:format)                  contacts#new
               offerings GET    /offerings(.:format)                   pages#offerings

我希望创建一条新的路由(因为它适用于其他几页),但是它没有起作用,我不确定为什么。我将在5到6页上重复此过程,因此,我想确保可以首先正确完成操作。

0 个答案:

没有答案