Я новичок в rails. Действие delete, похоже, не находит мои @events и говорит NoMethodError. Я что-то здесь упускаю? Создание частей работает как талисман, но удаление link_to всегда выдает ошибку.
Контроллер моих событий и его действие: -
`` `
before_action :find_occasion
before_action :find_event, only: [:destroy]
def create
@event = @occasion.events.create(params[:event].permit(:name, :location, :description, :isMakeAhead))
redirect_to occasion_path(@occasion)
end
def destroy
@event.destroy <-- This line shows error while clicking on the link
redirect_ to occasion_path(@occasion)
end
private
def find_occasion Got occasion id from here
@occasion = Occasion.find(params[:occasion_id])
end
def find_event Got event id from here
@event= @occasion.events.find(params[:id])
end
end
And my views:-
```
<%= event.name %>
<%= event.location %>
<%= event.description %>
<p> <%= link_to "Delete Event", [event.occasion, event], method: :delete, data: {confirm: "Are you sure?"} %></p>
# I have tried the button_to too but it doesn't work.
Это то, что появляется, когда я использую ЛУЧШИЕ ОШИБКИ GEM FILE.
Request parameters
{"_method"=>"delete", "authenticity_token"=>"something", "controller"=>"events", "action"=>"destroy", "occasion_id"=>"2", "id"=>"14"}
Rack session
(Object too large. Modify ActionDispatch::Request::Session#inspect or adjust BetterErrors.maximum_variable_inspect_size if you need to see it.)
Local Variables
Instance Variables
@_action_has_layout
true
@_routes
nil #routes shows nil i don't know why is that
@_action_name
"destroy"
@_response_body
nil
@marked_for_same_origin_verification
false
@_config
{}
@_params
<ActionController::Parameters {"_method"=>"delete", "authenticity_token"=>"something", "controller"=>"events", "action"=>"destroy", "occasion_id"=>"2", "id"=>"14"} permitted: false>