Ruby on rails 如何从视图中移动带有参数的实例\方法?
我的视图中有以下行代码:Ruby on rails 如何从视图中移动带有参数的实例\方法?,ruby-on-rails,ruby-on-rails-3,model-view-controller,methods,Ruby On Rails,Ruby On Rails 3,Model View Controller,Methods,我的视图中有以下行代码: <td> Model.some_instance_method(args) </td> Model.some_实例_方法(args) 我想澄清这一点。下面我粘贴整个代码 你没有非常清楚地说明你的目标是什么。假设您只想让它成为更地道的rails代码,类似这样的代码会更简洁: class PinnedContent < ActiveRecord::Base def reports PinnedContentReport.whe
<td> Model.some_instance_method(args) </td>
Model.some_实例_方法(args)
我想澄清这一点。下面我粘贴整个代码
你没有非常清楚地说明你的目标是什么。假设您只想让它成为更地道的rails代码,类似这样的代码会更简洁:
class PinnedContent < ActiveRecord::Base
def reports
PinnedContentReport.where("pinned_content_id = ?", self.id).count
end
end
class PinnedContent
在你看来:
<% @reported_pinned_contents.each do |reported_pinned_content| %>
<tr>
<td><%= reported_pinned_content.id %></td>
<td><%= reported_pinned_content.reports %></td>
<td></td>
</tr>
<% end %>