开始通过 Lynda 学习 Ruby on Rails - 非常兴奋,并且正在尽我最大的努力练习。我正在关注练习,但培训是基于 Rails 3 - 到目前为止,有些用途不被接受。
情况如下:
我到达主题/新的创建表单填写表单得到以下错误作为回报
没有路线匹配 [POST] "/subjects/create"
Rails.root:/Users/alpozenalp/Sites/simple_cms
我花了最后 2 个小时在 stackoverflow、rail guide 和所有其他资源中徘徊 - 尝试了许多变体,但无法超越这个阶段。
对你的帮助表示感谢。
路线.rb
SimpleCms::Application.routes.draw do
root :to => "demo#index"
get ':controller(/:action(/:id(.:format)))'
end
subject_controller.rb
class SubjectsController < ApplicationController
def index
list
render('list')
end
def list
@subjects = Subject.order("subjects.position ASC")
end
def show
@subject = Subject.find(params[:id])
end
def new
@subject = Subject.new
end
def create
# Instantiate a new object using form parameters
@subject = Subject.new(params[:subject])
# Save the object
if @subject.save
# If save succeeds, redirect to the list action
redirect_to(:action => 'list')
else
# If save fails, redisplay the form so user can fix problems
render('new')
end
end
end
新的.html.erb
<%= link_to("<< Back to List", {:action => 'list'}, :class => 'back-link') %>
<div class="subject new">
<h2>Create Subject</h2>
<%= form_for(:subject, :url => {:action => 'create'}, :method => :post) do |f| %>
<table summary="Subject form fields">
<tr>
<th>Name</th>
<td><%= f.text_field(:name) %></td>
</tr>
<tr>
<th>Position</th>
<td><%= f.text_field(:position) %></td>
</tr>
<tr>
<th>Visible</th>
<td><%= f.text_field(:visible) %></td>
</tr>
</table>
<div class="form-buttons">
<%= submit_tag("Create Subject") %>
</div>
<% end %>
</div>