0

ROR を初めて使用するのですが、場所を編集すると次のエラーが表示されます No route matches [POST] "/admin/locations/1"

ここで私はレール3.2.12を使用しています

これが私のロケーションコントローラーです

class Admin::LocationsController < ApplicationController


def index
    @location= Location.order("location desc")
end

def new
    @location=Location.new
end

def create
    @location = Location.new(params[:location])
    if @location.save
     # flash[:notice] = 'Location is successfully added in to list.'
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
end

def edit
   @location = Location.find(params[:id])
end

def update
    @location = Location.find(params[:id])
    if @location.update_attributes(params[:location])
      #flash[:notice] = 'Category is successfully updated.'
      redirect_to :action => 'index'
    else
      render :action => 'index'
    end
end

end

これは私の edit.html.erb です

<h2>Edit Location</h2>
<%= simple_form_for(:location, :url => {:action => 'update', :id => @location.id}) do |f| %>
    <%= render(:partial => 'form', :locals => {:f => f}) %>  
    <%= submit_tag("Update",) %> <%= link_to("cancle", {:action => 'index'} )%>

<%end%>

これは私のroute.rbです

GuestHouse::Application.routes.draw do
  devise_for :customers

  namespace :admin do
    resources :locations
  end

そして私の index.html.erb では <%= link_to("Edit", {:action => 'edit', :id => location.id}, :class => 'btn btn-info')%> として

4

3 に答える 3

0

PUT編集フォームの場合、 の代わりに メソッドを使用したいと思うでしょうPOST。ただし、[SimpleForm][1] を使用しているように見えますが、これは通常、特定のモデルのパスの構築を処理します。Locationへの呼び出しでインスタンスを渡さない理由はありますsimple_form_forか? 私は次のようなものを期待します:

<%= simple_form_for @location do |f| %>
...
于 2013-03-21T06:00:45.227 に答える
0
<%= simple_form_for(:location, 
  :url => {:action => 'update', :id => @location.id},
  :method => 'put' ) do |f| %>

メソッドを渡すsimple_form_for

于 2013-03-21T06:03:42.670 に答える
0

ここでは、次のような admin/location のルートを示します。

      admin_locations GET /admin/locations(.:format) admin/locations#index
                      POST /admin/locations(.:format) admin/locations#create
   new_admin_location GET /admin/locations/new(.:format) admin/locations#new
  edit_admin_location GET /admin/locations/:id/edit(.:format) admin/locations#edit
       admin_location GET /admin/locations/:id(.:format) admin/locations#show
                      PUT /admin/locations/:id(.:format) admin/locations#update
                      削除 /admin/locations/:id(.:format) admin/locations#destroy

したがって、フォームを「更新」アクションに送信する場合は、以下のようにパスを指定する必要があります。

<%= simple_form_for @location, :url => admin_location_path(@location),:html => { :method => "post"} do |f| %>
于 2013-03-21T06:07:54.317 に答える