开发者

Rails help counting rows

I am having a problem counting my rows in Konkurrancers table.

I have tried this, but it dos not work it render the page but it dont display the number of konkurrancers.

My application controller:

class ApplicationController < ActionController::Base
  protect_开发者_运维百科from_forgery
  require 'dynamic_form' 
@konkurrencerall = Konkurrancer.find(:all).count
end

My layout file:

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <html>
    <head>
      <title>Konkurranceportalen</title>
      </head>
    <body>
    <h1>Velkommen til Konkurranceportalen er kan du vælge imellem <span class="nummer"><%= @konkurrencerall %></span> <b>gratis</b> konkurrancer! </h1>
<%= yield %>
    </body>
    </html>


You'll want to run any logic that should execute every request into a before_filter:

require 'dynamic_form'

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :count_kunkurrancers

  def count_kunkurrancers
    @konkurrencerall = Konkurrancer.count
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜