我是 Rails 的新手,正在努力理解结构以及方法应该在哪里以及如何实例化。我现在很困惑自己。
从问题来看,这非常有效,这不符合 MCV 规则。
<% @showblog.showruns.group(:spec_vote).count.each do |spec,count| %>
Spec: <%=" #{spec}"%> Votes: <%=" #{count}" %> <br/>
<% end %>
我的观点应该是 <%= @voted.inspect %> 或类似的。
与其他地方的所有其他东西。在某些情况下,视图上显示的{}
只是 nil 或 nil 本身。
我最近的尝试:
class Voted < ActiveRecord::Base
def voted(spec,count)
@showblog = Showblog.find(params[:showblog_id])
@voted = @showblog.showruns.group(:spec_vote).count.each do |spec,count|
" Spec:#{spec} Votes: #{count}"
end end end
这有一个零。
我已经在不同的地方添加了这个来尝试看看出了什么问题,但即使出现“无方法错误”,我仍然不知道我应该在哪里看到它。
logger.error "--------(some word so I know the file name)-------#{@showblog.inspect}" 我的应用在 heroku.com
class Showblog < ActiveRecord::Base (parent) has_many :showruns, dependent: :destroy end
class Showrun < ActiveRecord::Base (child) belongs_to :showblog end
两个控制器都包含正常的 CRUD 并且工作正常。