Я использовал злую драгоценность для своей формы. Дело в том, что пользователь загружает фотографию, которую они могут видеть на той же странице, что и ..../steps/picture
. На странице изображения пользователь может уничтожить изображение. Когда пользователь нажимает, я бы хотел, чтобы они перенаправляли страницы шагов/изображений, но все, что я пробовал, я получаю ошибку. Лодка и изображение связаны, но не вложенные маршруты.Злой, после удаления действия redirect_to
вот мой контроллер изображения #destroy
action;
Защиту уничтожить
@picture = @boat.pictures.find(params[:id])
if @picture.destroy
######SOMETHING GOES HERE#########
flash[:notice] = "Successfully destroyed picture."
else
render json: { message: @picture.errors.full_messages.join(',') }
end
торцевую
#boat_steps
контроллер;
class BoatStepsController < ApplicationController
include Wicked::Wizard
before_action :logged_in_user
steps :model, :pricing, :description, :features, :picture
def show
@boat = current_user.boats.last
case step
when :picture
@picture = @boat.pictures.new
@pictures = @boat.pictures.all
end
render_wizard
end
def update
@boat = current_user.boats.last
@boat.update(boat_params)
case step
when :picture
@picture.update(picture_params)
end
render_wizard @boat
end
private
def finish_wizard_path
new_boat_picture_path(@boat, @picture)
end
def boat_params
params.require(:boat).permit(......)
end
def picture_params
params.require(:picture).permit(......)
end
end
EDIT 1:
>rake routes
Prefix Verb URI Pattern Controller#Action
update_years GET /boats/update_years(.:format) boats#update_years
update_models GET /boats/update_models(.:format) boats#update_models
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
boat_pictures GET /boats/:boat_id/pictures(.:format) pictures#index
POST /boats/:boat_id/pictures(.:format) pictures#create
new_boat_picture GET /boats/:boat_id/pictures/new(.:format) pictures#new
edit_boat_picture GET /boats/:boat_id/pictures/:id/edit(.:format) pictures#edit
boat_picture GET /boats/:boat_id/pictures/:id(.:format) pictures#show
PATCH /boats/:boat_id/pictures/:id(.:format) pictures#update
PUT /boats/:boat_id/pictures/:id(.:format) pictures#update
DELETE /boats/:boat_id/pictures/:id(.:format) pictures#destroy
boats GET /boats(.:format) boats#index
POST /boats(.:format) boats#create
new_boat GET /boats/new(.:format) boats#new
edit_boat GET /boats/:id/edit(.:format) boats#edit
boat GET /boats/:id(.:format) boats#show
PATCH /boats/:id(.:format) boats#update
PUT /boats/:id(.:format) boats#update
boat_steps GET /boat_steps(.:format) boat_steps#index
POST /boat_steps(.:format) boat_steps#create
new_boat_step GET /boat_steps/new(.:format) boat_steps#new
edit_boat_step GET /boat_steps/:id/edit(.:format) boat_steps#edit
boat_step GET /boat_steps/:id(.:format) boat_steps#show
PATCH /boat_steps/:id(.:format) boat_steps#update
PUT /boat_steps/:id(.:format) boat_steps#update
DELETE /boat_steps/:id(.:format) boat_steps#destroy
password_resets_new GET /password_resets/new(.:format) password_resets#new
password_resets_edit GET /password_resets/edit(.:format) password_resets#edit
profiles_edit GET /profiles/edit(.:format) profiles#edit
sessions_new GET /sessions/new(.:format) sessions#new
root GET / main#home
help GET /help(.:format) main#help
about GET /about(.:format) main#about
contact GET /contact(.:format) main#contact
signup GET /signup(.:format) users#new
login GET /login(.:format) sessions#new
POST /login(.:format) sessions#create
logout DELETE /logout(.:format) sessions#destroy
edit_account_activation GET /account_activations/:id/edit(.:format) account_activations#edit
password_resets POST /password_resets(.:format) password_resets#create
new_password_reset GET /password_resets/new(.:format) password_resets#new
edit_password_reset GET /password_resets/:id/edit(.:format) password_resets#edit
password_reset PATCH /password_resets/:id(.:format) password_resets#update
PUT /password_resets/:id(.:format) password_resets#update
EDIT:
лодка шаги контроллер
class BoatStepsController < ApplicationController
include Wicked::Wizard
before_action :logged_in_user
steps :model, :pricing, :description, :features, :picture
def show
@boat = current_user.boats.last
case step
when :picture
@picture = @boat.pictures.new
@pictures = @boat.pictures.all
end
render_wizard
end
def update
@boat = current_user.boats.last
@boat.update(boat_params)
case step
when :picture
@picture.update(picture_params)
end
render_wizard @boat
end
private
def finish_wizard_path
new_boat_picture_path(@boat, @picture)
end
def boat_params
params.require(:boat).permit(:brand, :year, :model, :captained, :boat_type, :daily_price, :boat_length, :listing_tagline, :listing_description, :boat_category, :hull_material, :mast_material, :capacity, :sleeping_capacity, :private_staterooms, :fuel_type, :engine_horsepower, :fuel_capacity, :fuel_consumption, :draft)
end
def picture_params
params.require(:picture).permit(:name, :boat_id, :image)
end
end
Вам просто нужно использовать 'redirect_to'. Если у вас есть сомнения, отправьте «рейк-маршруты» в свой вопрос. –
здесь Я отредактировал вопрос – Shalafister
Какая ошибка вы получали? – RichardAE