删除操作后的邪恶redirect_to

时间:2015-04-27 12:25:09

标签: ruby-on-rails controller gem destroy

我使用了邪恶的宝石作为我的形式。当用户上传照片时,他们可以在与..../steps/picture相同的页面上看到。在图片页面,用户可以破坏图片。当用户点击我希望他们重定向到步骤/图片页面,但无论我尝试什么,我都会得到错误。船和图片相关但不是嵌套路线。

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

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

#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

1 个答案:

答案 0 :(得分:1)

对于邪恶的向导,在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)。生成的网址应为/boat_steps/picture

相关问题