邪恶,删除操作后 redirect_to

Wicked, after delete action redirect_to

我的表格使用了 wicked gem。问题是当用户上传照片时,他们可以在与 ..../steps/picture 相同的页面上看到。在图片页面用户可以销毁图片。当用户点击时,我希望他们进入 redirect_to steps/picture 页面,但无论我尝试什么,我都会遇到错误。船和图片关联但不嵌套的路线。

这是我的图片控制器#destroy动作;

def 销毁

@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

编辑 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

编辑:

船步控制器

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

在 wicked wizards 上,视图上有可用的路径助手,但 rake routes

尝试redirect_to wizard_path(:picture)

您可以在此处找到有关可供查看的邪恶帮手的更多信息:https://github.com/schneems/wicked#quick-reference

这些助手将在使用 render_wizard 呈现的视图中可用。在向导之外,该步骤作为 RESTful 路由的 :id 传递。 要重定向到图片步骤中的 boat_steps/show,请尝试 redirect_to boat_step_path(id: :picture)。生成的 url 应该是 /boat_steps/picture.