문제

In a very simple rails project from a tutorial I run rails generate scaffold Event title:string date:date description:text. Everything is ok except that when I open the EventsController.rb I see that the show method is empty:

def show
end

In the video of the course I see that this method is not supposed to be empty and should contain things like @event = Event.find(params[:id]). What could possibly be the problem?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top