访问用户配置文件时未定义的局部变量或方法“user”

时间:2013-11-29 19:59:40

标签: ruby-on-rails ruby

以下是我收到的错误图片的链接:

http://gyazo.com/fb646e7da96913eeb5acdf39adfc8865

这是我的UsersController:

class UsersController < ApplicationController
  def show
    @user = User.find_by_username(params[:id])
  end
end

以下是用户个人资料的显示视图:

<strong><%= user.username %></strong> <br>
<strong><%= user.name %></strong>



<div id="things" class="transitions-enabled">
  <% @user.things.each do |thing| %>
    <div class='panel panel default'>
    <div class="box">
      <%= link_to image_tag(thing.image.url(:medium)), thing %>
      <div class='panel-body'>
      <strong><p><%= thing.title %></p></strong>
      <p><%= thing.description %></p>
      By <%= link_to thing.user.username, thing.user %>

      <% if thing.user == current_user %>
        <%= link_to edit_thing_path(thing) do %>
        <span class='glyphicon glyphicon-edit'></span> Edit
      <% end %>
      <%= link_to thing_path(thing), method: :delete, data: { confirm: 'Are you sure?' } do %>
        <span class='glyphicon glyphicon-trash'></span> Delete
      <% end %>
      </div>
      <% end %>
      </div>
    </div>
  <% end %>
</div>

1 个答案:

答案 0 :(得分:2)

<strong><%= @user.username %></strong>  
<strong><%= @user.name %></strong>

@user代替user 阅读Class and Instance Variables In Ruby 并编辑您的HTML代码