2011-08-21 64 views
0

如果我有一个名为Ece的控制器。它存储了很多课程。现在,如果用户在特定课程的演示页面上。我怎么知道哪个Ece对象的显示页面被显示。那是我想访问当前的Ece对象。最终我想这样做到目前的ece对象rails代码中的当前对象

@code = current_ece.course_code # assuming current_ece means the current object 

我想使用@code用于其他目的。

where course_code是其中的一列。我想在你show行动,你将抓住当前对象,并把它放在一个实例变量来做到这一点只在当前欧洲经委会对象

回答

1

通常情况下:

def show 
    @ece = Ece.find(params[:id]) 
    respond_to do |format| 
    format.html # show.html.erb 
    format.xml { render :json => @ece } 
    end 
end 

然后,你可以使用@ece您的视图中。阅读Getting Started with Rails [Rails 3/edge link]指南了解更多信息。