I have used wicked gem for my form. The thing is when user uploads photo they can see at the same page as ..../steps/picture
. At Picture page user can destroy the picture. When user clicks I would like them to redirect_to steps/picture page but whatever I tried I get error on that. Boat and Picture associated but not nested routes.
here is my picture controller #destroy
action;
def destroy
@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
end
#boat_steps
controller;
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:
Boat steps controller
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
On wicked wizards there are path helpers available on views that don't show on rake routes
.
Try redirect_to wizard_path(:picture)
You can find more information about wicked helpers available to views here: https://github.com/schneems/wicked#quick-reference
These helpers will be available on views rendered using render_wizard
. Outside of the wizard, the step is passed as the :id
of the RESTful route.
To redirect to boat_steps/show on the picture step try redirect_to boat_step_path(id: :picture)
. The url generated should be /boat_steps/picture
.