Amzziipan
Amzziipan

Reputation: 91

Ruby on Rails 3, Passing Params?

I'm currently trying to get all of the Events made by a User in my Ruby on Rails app.

Rails version = 3.0.9 Ruby version = 1.9.2

User has_many :events
Event belongs_to :user

admin_controller.rb: (Used for displaying the admin section of the app)

class AdminController < ApplicationController

  load_and_authorize_resource

  def index
    @topuploaders = User.find(:all, :include => :events).sort_by { |u| -u.events.count }.first(5)
    @topflyers = Event.all(:limit =>10, :order => 'viewcount DESC')
  end

  def users
    @users = User.all
  end

  def flyers
    @events = Event.all
  end

  def get_flyers
    @user = User.find(params[:id])
  end

end

The function users finds and displays all of the Users by name. I am stuck on how to make a link to a page that will display all of the events created by a user.

I tried to use the:

def get_flyers
        @user = User.find(params[:id])
end

And then display the names of the flyers in the view, but this did not work.

Any suggestions would be greatly appreciated. I am quite new hear so I'm not sure if I've given enough detail, so please bear with me.

Thankyou in advance.

Upvotes: 0

Views: 163

Answers (1)

ankit
ankit

Reputation: 3358

Simply modify your get_flyers function to

@flyers=User.find(params[:id]).events

Then, @flyers will contain an array of events for that user, which you can display from your view.

Upvotes: 2

Related Questions