HarryLucas
HarryLucas

Reputation: 159

Link_to 'xyz: @xyz.size', @xyz Rails

I am trying to make it so that this line here:

<%= link_to 'Projects: @projects.size', '#', class: 'btn btn-md btn-primary btd' %>

Will create a button that has the text 'Projects: ' and then the number of projects that there are currently in the database for this user.

Also because of this, does it mean I would use something similar to

@projects.size.where(:user_id == current_user)

Upvotes: 0

Views: 28

Answers (1)

Taryn East
Taryn East

Reputation: 27747

Try this instead: "Projects: #{@projects.size}" (note the double quotes)

You used a plain-old string, and it was literally writing out Projects: @projects.size when you really wanted an interpreted string (using double quotes) and the special #{} syntax that actually evaluates the code inside.

For projects belonging to the current-user. I'd recommend something like this:

current_user.projects.count

Upvotes: 1

Related Questions