当我编辑我的位置时,我是 ROR 的新手,它会给我以下错误
No route matches [POST] "/admin/locations/1"
这里我使用的是 rails 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')%>