我前不久发布了此内容,但是尝试了所有操作,但仍然无法在我的网站上创建新页面。
如果我输入错了,请纠正我,但是使用红宝石制作新路线/页面的3个步骤是:
app/controllers/pages_controller
中添加一个空的功能/控制器操作:def "page name" end
touch app/views/pages/page_name.html.erb
get 'page_name', to: 'pages#page_name'
中添加config/routes.rb
我尝试使用2个单独的名称进行尝试,但都没有导致创建新的页面/路由。我是否缺少某种终端命令或其他内容?当我执行rails routes
时,它显示了我创建的其他路径,例如offerings
,但没有显示public_speaking
(我还尝试通过执行以下3个步骤来创建test
路径而且也没有出现)。
我的代码:
class PagesController < ApplicationController
# GET request for / which is our home page
def home
@basic_plan = Plan.find(1)
@pro_plan = Plan.find(2)
end
def about
end
def offerings
end
def public_speaking
end
end
然后在routes.rb
中,我尝试使用相同的过程(将get 'public_speaking'
添加到pages#public_speaking
中)
Rails.application.routes.draw do
root to: "pages#home"
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 'offerings', to: 'pages#offerings'
get 'public_speaking', to: 'pages#public_speaking'
end
我还在views文件夹中创建了一个同名文件public_speaking.html.erb
。
我希望创建一条新路线(因为它适用于offerings
和about
),但是它没有用,我不确定为什么。我将重复此过程5至6页,所以我想确保可以正确完成操作
请让我知道这里是否有其他代码位置,我将提供任何代码。
答案 0 :(得分:0)
我认为您的页面应该位于views / pages / public_speaking.html.erb中,在第一种情况下,我将使用Rails工具创建控制器:
[<keras.layers.convolutional.Conv1D object at 0x7fe6dc8eb400>]
它将创建您需要的所有东西,然后转到➜ rails g controller Pages home about offerings public_speaking
Running via Spring preloader in process 31236
create app/controllers/pages_controller.rb
route get 'pages/home'
get 'pages/about'
get 'pages/offerings'
get 'pages/public_speaking'
invoke erb
create app/views/pages
create app/views/pages/home.html.erb
create app/views/pages/about.html.erb
create app/views/pages/offerings.html.erb
create app/views/pages/public_speaking.html.erb
invoke test_unit
create test/controllers/pages_controller_test.rb
invoke helper
create app/helpers/pages_helper.rb
invoke test_unit
invoke assets
invoke coffee
create app/assets/javascripts/pages.coffee
invoke scss
create app/assets/stylesheets/pages.scss
,您将看到所有生成的html.erb模板,然后在模板内部编写静态http页面:
app/views/pages
然后启动您的Rails应用
rails服务器-p 5000
并转到http://localhost:5000/pages/public_speaking.html,您将在其中拥有静态页面