rails use counts in diferent views

Posted by Oluf Nielsen on Stack Overflow See other posts from Stack Overflow or by Oluf Nielsen
Published on 2010-05-23T15:23:22Z Indexed on 2010/05/23 15:31 UTC
Read the original article Hit count: 543

Hello i guess this is going to be pretty noob question.. But..

I have an scaffold called list, which has_many :wishes. And with that information in my model, I can in my list view use this code

<%=h @list.wishes.count %>

well now I have made an controller called statusboard.. And in that' I have 3 functions.. Or how to say it.. but it is Index, loggedin, loggedout.. And .. In loggedin and in the file #app/views/statusboard/loggedin.html.erb i want to display this..

Howdy {Username}, you have made {count lists} lists, and {count wishes} wishes

here is that i figured i should write in my file..

Howdy {Username}, you have made <%=h @user.list.count %> lists, and <%=h @user.wishes.count %> wishes

my list model is like this =

class List < ActiveRecord::Base

  attr_accessible :user_id, :name, :description

  belongs_to :users

  has_many :wishes

end

and my wish model is like this =

class Wish < ActiveRecord::Base

  attr_accessible :list_id, :name, :price, :link, :rating, :comment

  belongs_to :list

end

and last my user model is like this =

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:

  # :token_authenticatable, :lockable and :timeoutable

  devise :database_authenticatable, :registerable,# :confirmable,

             :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model

  attr_accessible :email, :password, :password_confirmation

  has_many :lists

end

i hope someone can help me :-)! / Oluf Nielsen

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby