【发布时间】:2014-01-08 06:03:56
【问题描述】:
我正在尝试学习 RoR。 我的控制器是
class SectionController < ApplicationController
def new
if request.post?
u=SectionMst.new( :section_name => params[:section_name])
u.save
redirect_to("/section")
else
render
end
end
def index
@sections = SectionMst.all
end
def destroy
u=SectionMst.destroy(params[:id])
u.save
redirect_to("/section")
end
def edit
@user = SectionMst.find(params[:id])
end
end
和 index.html.erb 是
<%= link_to "Edit", edit_section_path(section.id), method: :edit %>
rake 路线是
section_new POST /section/new(.:format) section#new
POST /section/:id/edit(.:format) section/:id#edit
section_index GET /section(.:format) section#index
POST /section(.:format) section#create
new_section GET /section/new(.:format) section#new
edit_section GET /section/:id/edit(.:format) section#edit
section GET /section/:id(.:format) section#show
PUT /section/:id(.:format) section#update
DELETE /section/:id(.:format) section#destroy
routes.rb 是
post "section/new"
post "section/:id/edit"
resources :section
我得到了 路由错误 未初始化的常量部分
如果我删除 routes.rb 的第二行 然后我得到 路由错误 没有路线匹配 [POST] "/section/3/edit"
不知道为什么???
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3