ActionNotFound(无法为 UsersController 找到操作 'show'):ruby rails

ActionNotFound (The action 'show' could not be found for UsersController): ruby on rails

每次单击用户名时都会出现此错误(在此 your_list.html.erb 中找不到 UsersController 的操作 'show')

这是your_list.html.erb

<span class="pull-right text-center">
  <%= image_tag avatar_url(list.item.user), class: "img-circle 
             avatar-medium" %></br>
   <%= link_to user_path(list.item.user) do %>
                <%= list.item.user.fullname %>
   <% end %>
</span>

这是我的用户控制器

 class UsersController < ApplicationController
    def shown
    @user = User.find(params[:id])
    @items = @user.items
   end
 end

这是我单击按钮时命令行的图像

正确的错字应该是 show 而不是 shown

def show
  @user = User.find(params[:id])
  @items = @user.items
end

为您的 users 文件夹创建 show 模板,例如 show.html.erb

确保重新检查 routes.rb 中的路由条目,例如

resources :users

和控制器将动作名称 shown 重命名为 show 并渲染相应的 your_list.html.erb 文件

def show
  @user = User.find(params[:id])
  @items = @user.items
  render :template => 'products/your_list'
end