如果通过此’.any’电话找到帖子,如何收到帖子的ID? % if @posts.any? {|p| p.title == my_title} % 你应该这样做: % if (post = @posts.detect {|p| p.title == my_title} ) % Post ID: %= post.id %% end %
<% if @posts.any? {|p| p.title == my_title} %>你应该这样做:
<% if (post = @posts.detect {|p| p.title == my_title} ) %> Post ID: <%= post.id %> <% end %>