我以前做过,但是在向我的rails服务器添加新页面和新路径时遇到问题。
几乎,我想添加一个新页面,然后在我的网站上链接到该页面......但是当我执行"rails routes"命令时,我无法使路线创建步骤生效并显示。
我之前在 pages#offerings 的"产品"页面和"public_speaking"中再次这样做过,但我无法让 ruby 使用相同的步骤创建第三个页面,或者看起来是这样。
我开始转到页面控制器并添加"def public_speaking"和"end":
页面控制器
def home
end
def about
end
def offerings
end
def public_speaking
end
def nonverbal
end
end
路线.rb
然后在 Routes.rb 中,我尝试使用相同的过程(将 get 'public_speaking' 添加到:"pages#public_speaking")
root to: "pages#home"
get 'home/public_speaking'
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'
get 'pages/nonverbal'
get 'nonverbal', to: 'pages#nonverbal'
end
我尝试了获取"页面",到:"页面#页面"和获取"页面/页面"方法来添加路由,但都不起作用。
查看文件
我还在视图文件夹中创建了一个同名的文件"nonverbal.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
我确实有 2 条产品路线,这是否表明存在任何问题?
我做错了什么/错过了什么来创建这条新路径?是否有一些命令来执行此链接或其他内容?
我希望创建一条新路线(因为它适用于"产品"),但是它没有奏效,我不确定为什么。我将重复此过程 5-6 页,所以我想确保我可以做对
我不知道为什么在您的路线中生成offerings GET /offerings(.:format) pages#offerings
以及从哪里生成。由于某种原因,您的routes.rb
似乎不对应。我希望看到nonverbal
路线在哪里。并且还有/非语言和/页面/非语言等。是故意的吗?
但是,我建议您尝试更通用的方法,因为您想使用PagesController.rb
来呈现各种页面。像这样的东西怎么样
get "pages/:page", to: "pages#serve"
和在 PagesController.rb 中
def serve
render "pages/#{params[:page]}"
end
如果您愿意,可以向路由添加约束