gpt4 book ai didi

ruby-on-rails - Rails 路由命名空间错误?

转载 作者:太空宇宙 更新时间:2023-11-03 18:10:05 24 4
gpt4 key购买 nike

所以我使用“成员”命名空间创建了两条路由,当我执行 rake 路由时,它不显示我应该使用的路径,它只是显示这个;-

GET /user/:id(.:format) member/member#

GET /user/:id/edit(.:format) member/member#edit

当我使用这一行时它返回一个错误;-

<li><%= link_to image_tag(current_user.picture, class: "user-picture"), {:controller => "Member/Member", :action => :show} if current_user.picture? %></li>

并得到这个错误;-

No route matches {:action=>"show", :controller=>"Member/Member"}

这是我的路线;-

  scope module: 'member' do
get '/user/:id', to: 'member#show'
get '/user/:id/edit', to: 'member#edit'
end

我的全部佣金路线;-

                  Prefix Verb   URI Pattern                    Controller#Action
charges GET /charges(.:format) charges#index
POST /charges(.:format) charges#create
new_charge GET /charges/new(.:format) charges#new
edit_charge GET /charges/:id/edit(.:format) charges#edit
charge GET /charges/:id(.:format) charges#show
PATCH /charges/:id(.:format) charges#update
PUT /charges/:id(.:format) charges#update
DELETE /charges/:id(.:format) charges#destroy
new_admin_session GET /admins/sign_in(.:format) devise/sessions#new
admin_session POST /admins/sign_in(.:format) devise/sessions#create
destroy_admin_session DELETE /admins/sign_out(.:format) devise/sessions#destroy
admin_unlock POST /admins/unlock(.:format) devise/unlocks#create
new_admin_unlock GET /admins/unlock/new(.:format) devise/unlocks#new
GET /admins/unlock(.:format) devise/unlocks#show
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
root GET / public/public#homepage
cart_add_item POST /cart_add_item(.:format) cart/cart#add_item_to_cart
empty_cart GET /empty_cart(.:format) cart/cart#empty_cart
destroy_cart GET /destroy_cart(.:format) cart/cart#destroy
cart GET /cart(.:format) cart/cart#show
product_new GET /product/new(.:format) admin/product#new
product_create POST /product/create(.:format) admin/product#create
product_destroy GET /product/destroy(.:format) admin/product#destroy
GET /user/:id(.:format) member/member#show
GET /user/:id/edit(.:format) member/member#edit

我如何访问我的显示操作和我的编辑操作?

最佳答案

我建议你在路由中使用 Rails 内置的 resources:

scope module: 'member' do
resources :users, only: [:show, :edit]
end

然后您将可以调用以下路径:

member_user_path(current_user) # /member/users/:id/ -> Show action
edit_member_user_path(current_user) # /member/users/:id/edit -> Edit action

而不是使用老式的链接定义:

{:controller => "member/member", :action => :show}

关于ruby-on-rails - Rails 路由命名空间错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com