Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以得到
<% if current_user %>
去工作。但是我希望能够使用像
<% if current_user=(user) %>
或类似的东西。我怎么能用巫术做到这一点?
您正在尝试在需要比较运算符的地方使用赋值运算符。大概应该是这样的:
<%= if @user == current_user %> <!-- Do stuff --> <% end %>
请记住,您需要@user通过在控制器操作中分配实例变量来访问它:
@user
class UsersController < ApplicationController def show @user = User.find(params[:id]) end end