2

我是 Ruby on Rails 的新手,这是我在 stackoverflow 上的第一篇文章。

我有这个页面,用户可以在其中选择他想要的功能。由于他选择了要素,该操作将他带到一个页面,在该页面中他可以查看选定要素的属性,并且对于每个选定要素,都有一个用于编辑要素的链接。我可以完美地编辑和更新功能,但我希望操作更新重定向到具有所选功能的页面,以便用户不必再次选择它们。

问题是当我这样做时redirect_to select_multiple_features_path,它不会导致 select_multiple 动作。我收到以下错误:


ActiveRecord::RecordNotFound in FeaturesController#show

找不到 id=select_multiple 的功能

服务器输出:http: //img138.imageshack.us/img138/1382/sfp4.jpg


控制器:

  def edit
    @feature = Feature.find(params[:id])
  end

  def update
    @feature = Feature.find(params[:id])    
    respond_to do |format|
      if @feature.update_attributes(params[:feature])
        format.html { redirect_to select_multiple_features_path, notice: 'Feature was successfully updated.' }
      else
        format.html { render action: "edit" }
        format.json { render json: @feature.errors, status: :unprocessable_entity }
      end
    end
  end

  def select_multiple
    if params[:features_ids].nil?
      @features = Feature.find(session[:features_ids])
    else
      @features = Feature.find(params[:features_ids])
      session[:features_ids] = params[:features_ids]
    end
  end

路线:

resources :attached_assets

resources :modifications

resources :maps

resources :coordinates

resources :results do
    collection do
      post 'select_number_of_groups'
    end
end


resources :features do
    collection do
      post 'select_multiple'
    end
end

resources :home

devise_for :users, :path => "auth", :path_names => { :sign_in => 'login', 
                                                     :sign_out => 'logout', 
                                                     :password => 'secret', 
                                                     :confirmation => 'verification', 
                                                     :unlock => 'unblock', 
                                                     :registration => 'register', 
                                                     :sign_up => 'cmon_let_me_in' 
                                                    }

devise_scope :user do
  root to: "devise/sessions#new"
end

任何想法?

4

1 回答 1

0

In your route, you're defining your post action but you aren't defining your get action. You have to define:

get 'features/select_multiple' => 'features#select_multiple'

or else it will assume that you're trying to use the #show action by default.

You can use rake routes in your console to show all your routes and matching actions

于 2013-08-05T13:42:53.497 回答