Мой вопрос: как я могу перенаправить на страницу показа событий после того, как были выполнены действия по удалению, созданию, обновлению.
Я новичок в рельсах, поэтому, пожалуйста, помогите мне в этом. У меня есть файл маршрутов, подобный этому.
resources :occasions do
resources :events
end
resources :events do
resources :event_details
end
Мой контроллер event_detail:
before_action :set_event
before_action :set_event_detail, except: [:new, :create]
def new
@event_detail = EventDetail.new
end
def create
@event_detail = EventDetail.new(event_detail_params)
@event_detail.event = @event
@event_detail.save
redirect_to
end
def edit
end
def update
@event_detail.update(event_detail_params)
end
def destroy
@event_detail.destroy
redirect_to ??
end
private
def set_event
@event = Event.find(params[:event_id])
end
def set_event_detail
@event_detail = EventDetail.find(params[:id])
end
def event_detail_params
params.require(:event_detail).permit(:capacity, :start_time, :end_time)
end
Теперь у меня есть много событий, как указано на маршрутах, а у событий много событий_деталей.Но в моем контроллере у меня нет повода, поэтому я не могу перенаправить на страницу http://localhost:3000/occasions/1/events/1 после того, как удалю или обновлю свой event_detail.
Файл моих маршрутов рейка
rake routes
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users(.:format) devise/registrations#create
teacher_students GET /teachers/:teacher_id/students(.:format) students#index
POST /teachers/:teacher_id/students(.:format) students#create
new_teacher_student GET /teachers/:teacher_id/students/new(.:format) students#new
edit_teacher_student GET /teachers/:teacher_id/students/:id/edit(.:format) students#edit
teacher_student GET /teachers/:teacher_id/students/:id(.:format) students#show
PATCH /teachers/:teacher_id/students/:id(.:format) students#update
PUT /teachers/:teacher_id/students/:id(.:format) students#update
DELETE /teachers/:teacher_id/students/:id(.:format) students#destroy
teachers GET /teachers(.:format) teachers#index
POST /teachers(.:format) teachers#create
new_teacher GET /teachers/new(.:format) teachers#new
edit_teacher GET /teachers/:id/edit(.:format) teachers#edit
teacher GET /teachers/:id(.:format) teachers#show
PATCH /teachers/:id(.:format) teachers#update
PUT /teachers/:id(.:format) teachers#update
DELETE /teachers/:id(.:format) teachers#destroy
occasion_events GET /occasions/:occasion_id/events(.:format) events#index
POST /occasions/:occasion_id/events(.:format) events#create
new_occasion_event GET /occasions/:occasion_id/events/new(.:format) events#new
edit_occasion_event GET /occasions/:occasion_id/events/:id/edit(.:format) events#edit
occasion_event GET /occasions/:occasion_id/events/:id(.:format) events#show
PATCH /occasions/:occasion_id/events/:id(.:format) events#update
PUT /occasions/:occasion_id/events/:id(.:format) events#update
DELETE /occasions/:occasion_id/events/:id(.:format) events#destroy
occasions GET /occasions(.:format) occasions#index
POST /occasions(.:format) occasions#create
new_occasion GET /occasions/new(.:format) occasions#new
edit_occasion GET /occasions/:id/edit(.:format) occasions#edit
occasion GET /occasions/:id(.:format) occasions#show
PATCH /occasions/:id(.:format) occasions#update
PUT /occasions/:id(.:format) occasions#update
DELETE /occasions/:id(.:format) occasions#destroy
event_event_details GET /events/:event_id/event_details(.:format) event_details#index
POST /events/:event_id/event_details(.:format) event_details#create
new_event_event_detail GET /events/:event_id/event_details/new(.:format) event_details#new
edit_event_event_detail GET /events/:event_id/event_details/:id/edit(.:format) event_details#edit
event_event_detail GET /events/:event_id/event_details/:id(.:format) event_details#show
PATCH /events/:event_id/event_details/:id(.:format) event_details#update
PUT /events/:event_id/event_details/:id(.:format) event_details#update
DELETE /events/:event_id/event_details/:id(.:format) event_details#destroy
events GET /events(.:format) events#index
POST /events(.:format) events#create
new_event GET /events/new(.:format) events#new
edit_event GET /events/:id/edit(.:format) events#edit
event GET /events/:id(.:format) events#show
PATCH /events/:id(.:format) events#update
PUT /events/:id(.:format) events#update
DELETE /events/:id(.:format) events#destroy
root GET / homeroutes#routes
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
Мой контроллер событий
# before_action :authenticate_user!
before_action :set_occasion, expect: [:index, :show]
before_action :set_event, except: [:new, :create]
# after_action :verify_authorized
def new
@event = Event.new
# authorize @event
end
def create
@event = Event.new(event_params)
@event.occasion = @occasion
# authorize @event
@event.save
redirect_to occasion_path(@occasion)
end
def edit
# authorize @event
end
def show
# authorize @event
end
def update
# authorize @event
@event.update(event_params)
redirect_to occasion_path(@occasion)
end
def destroy
# authorize @event
@event.destroy
redirect_to occasion_path(@occasion)
end
private
def set_event
@event = Event.find(params[:id])
end
def set_occasion
@occasion = Occasion.find(params[:occasion_id])
end
def event_params
params.require(:event).permit(:name, :location, :description, :isMakeAhead)
end
end
И мой файл просмотра в событии # Показать страницу:
<h1>Event Info</h1>
<table>
<thead>
<tr>
<td>Name</td>
<td>Location</td>
<td>Description</td>
<td>Make ahead</td>
<td>Capacity</td>
</tr>
</thead>
<tbody>
<tr>
<td><%= @event.name %></td>
<td><%= @event.location %></td>
<td><%= @event.description %></td>
<td><%= @event.isMakeAhead %></td>
</tr>
</tbody>
</table>
<%= render @event.event_details %>
<p><%= link_to "Create Time slots", new_event_event_detail_path(@event,@event_detail) %></p>
Я могу создать event_detail, но мне нужно обновить страницу и перейти к http://localhost:3000/occasions/1/events/1 вручную, чтобы увидеть новое создание.Есть ли способ после создания event_detail, я могу перенаправить обратно на эту страницу "http://localhost:3000/occasions/1/events/1". Любая помощь будет любезно оценена.
Ошибка, которую я получаю: введите описание изображения здесь