我正试着循环通过一个块,将通过短语,看看是否包括他们的推特。如果推特包括短语,他们应该收到“编辑”的div类。但是,我一直收到一个private method select called for "Walt":String错误。我是新手,所以请容忍我的代码。
查看:
<section id="tweets">
<ul>
<% tweet = @tweets.each do |tweet| %>
@<%= tweet.user.screen_name %>
<%= image_tag(tweet.user.profile_image_url) %>
<li><%= link_to tweet.text, "https://www.twitter.com/#{tweet.user.screen_name}=twitter&include_entities=true" %></li>
<% for blockedshows in current_user.blockedshows %>
<%= blockedshows.phrases %>
<% for phrases in blockedshows.phrases %>
<%= blocked = phrases.text %>
<%= result = blocked.select do |b| %>
<%= tweet.include? b %>
<% end %>
<% end %>
<% if result.empty? %>
<%= tweet %>
<% else %>
<%= content_tag(:div, class: 'redacted') {tweet} %>
<% end %>
<%end %>
模型
class Phrase < ActiveRecord::Base
belongs_to :tvshow
belongs_to :blockedshow
def select
end
end发布于 2013-12-24 16:25:23
被阻塞的变量已经包含了要与tweet进行比较的文本,并且尝试在其上执行select方法( string类的私有方法)。
重构您的代码
<% current_user.blockedshows.each do |blockedshow| %>
<% blockedshow.phrases.each do |phrase| %>
<% if tweet.text.include? phrase.text %>
<%= content_tag(:div, class: 'redacted') {tweet} %>
<% else %>
<%= tweet %>
<% end %>
<% end %>
<% end %>https://stackoverflow.com/questions/20763468
复制相似问题