我以前做过,但是在向Rails服务器添加新页面和新路径时遇到麻烦。
几乎,我想添加一个新页面,然后链接到我的网站上的该页面...但是我在使路线创建步骤生效并在执行“ railsroutes”命令时显示时遇到麻烦
我以前在pages#offings的“报价”页面上做了这个,而对于“ public_speaking”又是这样做的,但是我无法让红宝石使用相同的步骤来创建第三页,看来如此。
我开始转到页面控制器,并添加了“ def public_speaking”和“ end”:
def home
end
def about
end
def offerings
end
def public_speaking
end
def nonverbal
end
end
然后在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
我尝试将get'page'设置为:'pages#page'和get'pages / page'方法来添加路由,但均未成功。
我还在views文件夹中创建了一个同名文件“ 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页,所以我想确保可以正确完成操作
答案 0 :(得分:0)
我不知道为什么在您的路线中以及从何处生成offerings GET /offerings(.:format) pages#offerings
。您的routes.rb
似乎由于某些原因不匹配。我期望看到的nonverbal
路线在哪里。并且也有/ nonverbal和/ pages / nonverbal等。是故意的吗?
但是我建议您尝试一些更通用的方法,因为您想使用PagesController.rb
来呈现各种页面。
get "pages/:page", to: "pages#serve"
和在PagesController.rb
中def serve
render "pages/#{params[:page]}"
end
,如果您愿意,可以添加Constraints进行路由