【发布时间】:2014-10-24 07:07:45
【问题描述】:
我是 ruby on rails 的新手,所以请帮助我 :) 这是我的错误
NoMethodError in Welcome#sucess
Showing ..app/views/welcome/sucess.html.erb where line #8 raised:
undefined method `find_by' for #<ActiveRecord::Relation:0x41dca80>
Extracted source (around line #8):
5: <%= @user.pass%><br />
6: <% if current_user && current_user != @user %>
7: <% if current_user.following.include?(@user) %>
8: <%= form_for(current_user.following_relations.find_by(following_id: @user.id),
9: html: { method: :delete }) do |f| %>
10: <%= f.submit "Unfollow", class: "btn" %>
11: <% end %>
这是我的关系控制器
def destroy
user = Relations.find(params[:id]).following
current_user.unfollow(user)
redirect_to user
end
我的用户模型
def unfollow(other_user)
following_relations.find_by(following_id: other_user.id).destroy
end
请帮我解决这个问题
【问题讨论】:
-
您使用的是哪个版本的 Rails? find_by 仅适用于 >= 4.0 的 rails
-
我使用的是 rails 版本 3.2.19
标签: ruby-on-rails ruby