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
精彩评论