开发者

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 o开发者_开发知识库f 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜