0

在我运行的教程中的一个非常简单的 rails 项目中rails generate scaffold Event title:string date:date description:text。一切都很好,除了当我打开 EventsController.rb 时,我看到 show 方法是空的:

def show
end

在课程的视频中,我看到这个方法不应该是空的,应该包含@event = Event.find(params[:id]). 可能是什么问题?

4

1 回答 1

0

In Rails 4 the style is changed to getting particular resource based on id. So it is moved to before_folter section.

You controller may be like,

before_action :set_event, only: [:show, :edit, :update, :destroy]

def set_event
  @event = Event.find(params[:id])
end

Please see the controller private methods.

于 2013-07-24T10:12:39.470 回答