Displaying find.all from another view

I’ve got 2 controllers - user and club

I want to display all the clubs in a user view, how would i go about it?

All i seem to get is NoMethodError

Well, how are you currently going about it? Is Club.find_all not
working?

Jason

At the moment in the users controller i have:

def club
@club = Club.find_all
end

then in the user view (index) i have:

<% for user in @users %>

<%= club.id %>
<%= club.name %>

<% end %>

Am I going around it completely the wrong way? :expressionless:

It’s ok I’ve sorted it! It was me being a silly git!

Looks like you’re still not quite grasping what Controller classes are.
def
club; … end; is an action, code that will only be called when you
POST/GET
to /users/club. Looks like you want just /users/, so your index action
(def
index; … end;) is the one that should contain @club = Club.find_all.

Of course, the view is wrong as well.

Controller:

def index
@user = [user stuff]
@clubs = Club.find_all
end

View:

<% for club in @clubs %>
<%= club.id %>
<%= club.name %>
<% end %>

You should spend some more time looking through documentation on how to
use
Rails. The Agile Development with Rails is an excellent book to get you
started.

Jason

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs