Rails : 如何在不使用脚手架的情况下显示网页?
Rails : How to display web page without using scafold?
我在 Rails 中有一个 Web 应用程序。当用户登录时,用户必须能够访问他可以看到一些信息的网页。所以我从这样的菜单中创建了一个 link:
<li><a href="/users/ask">Ask data</a></li>
这是我的 routes.rb :
Rails.application.routes.draw do
...
as :user do
get 'users/candidat/sign_up', to: 'user/registrations#new', as: :candidat_registration
get 'users/recruteur/sign_up', to: 'user/registrations#new', as: :recruteur_registration
end
devise_for :users, controllers: { registrations: "user/registrations", sessions: "user/sessions" }
resources :users, only: [:index, :show, :edit, :update, :destroy] do
put "recommand", to: "users#recommand"
get '/users/ask' => 'users#ask'
end
get "/dashboard" => 'dashboard#index'
root to: "home#index"
end
这是我的网页 app/views/users/ask。html.erb:
<p>
Ask Data here
</p>
但是当我点击 link 时,我无法访问我的网页。
这里是 raltives 日志:
Started GET "/users/ask" for ::1 at 2016-04-13 10:50:49 +0200
Processing by UsersController#show as HTML
Parameters: {"id"=>"ask"}
[1m[35mUser Load (0.4ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 0 LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :set_user rendered or redirected
Completed 302 Found in 3ms (ActiveRecord: 0.4ms)
我不太了解 RoR,但我认为它与 routes.rb 中的配置有关。我总是生成带脚手架的页面。在此页面上,我不需要 CRUD 功能。请问有什么问题吗?如果您可以向我推荐一些资源,博客 post 以了解我遇到的问题,谢谢。
我有义务在控制器中传递请求吗?用户需要连接才能访问我的网页。
是否可以只配置路由和显示?
我认为这是路由错误。尝试改变
get 'askrecommandation' => 'users#ask'
至
get '/users/ask' => 'users#ask'
我在 Rails 中有一个 Web 应用程序。当用户登录时,用户必须能够访问他可以看到一些信息的网页。所以我从这样的菜单中创建了一个 link:
<li><a href="/users/ask">Ask data</a></li>
这是我的 routes.rb :
Rails.application.routes.draw do
...
as :user do
get 'users/candidat/sign_up', to: 'user/registrations#new', as: :candidat_registration
get 'users/recruteur/sign_up', to: 'user/registrations#new', as: :recruteur_registration
end
devise_for :users, controllers: { registrations: "user/registrations", sessions: "user/sessions" }
resources :users, only: [:index, :show, :edit, :update, :destroy] do
put "recommand", to: "users#recommand"
get '/users/ask' => 'users#ask'
end
get "/dashboard" => 'dashboard#index'
root to: "home#index"
end
这是我的网页 app/views/users/ask。html.erb:
<p>
Ask Data here
</p>
但是当我点击 link 时,我无法访问我的网页。
这里是 raltives 日志:
Started GET "/users/ask" for ::1 at 2016-04-13 10:50:49 +0200
Processing by UsersController#show as HTML
Parameters: {"id"=>"ask"}
[1m[35mUser Load (0.4ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 0 LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :set_user rendered or redirected
Completed 302 Found in 3ms (ActiveRecord: 0.4ms)
我不太了解 RoR,但我认为它与 routes.rb 中的配置有关。我总是生成带脚手架的页面。在此页面上,我不需要 CRUD 功能。请问有什么问题吗?如果您可以向我推荐一些资源,博客 post 以了解我遇到的问题,谢谢。 我有义务在控制器中传递请求吗?用户需要连接才能访问我的网页。 是否可以只配置路由和显示?
我认为这是路由错误。尝试改变
get 'askrecommandation' => 'users#ask'
至
get '/users/ask' => 'users#ask'