似乎我的“创建”操作没有发送我在“新”视图中输入的信息。我有一条路线叫
localhost:3000/zips
我有新页面的视图
<h1>
Zip Code Eligibility <font color="green">Add Zip Code</font>
</h1>
<p>
To <span class="hi">ADD</span> a zip code from the local delivery service, please enter the 5 digit zip code (6 in Canada) and click submit.
</p>
<%= form_for @zip do |z| %>
<p><%= z.label :zip %> <%= z.text_field :zip %> |
<%= z.label :state %> <%= z.text_field :state %>
</p>
<p><%= z.submit "Add Zip Code" %></p>
<% end %>
这是我的 zips_copntroller
class ZipsController < ApplicationController
def index
@zips = Zip.all
end
def show
@zip = Zip.find(params[:id])
end
def new
@zip = Zip.new
end
def create
@zip = Zip.new(params[:post])
if @zip.save
redirect_to zips_path, :notice => "Zipcode was saved sucessfully"
else
render "new"
end
end
def edit
end
def update
end
def destroy
end
end
现在,当我输入“91202”然后输入“CA”时,我单击提交...它提交并重定向到索引视图
<h1>
Pick-up/Delivery Eligibility
</h1>
<h3>
Based on U.S. Zipcode, Canadian Postal Code
</h3>
<p class="el">
To find out if you qualify for 4over’s local delivery service,
please enter your <nobr>U.S. 5 digit zip code, or</nobr> your
<nobr>Canadian 6 character Postal Code,</nobr> then click submit.
<h4>Current Eligible Zip Codes</h4>
<!-- Possible sample code for the display page when I get around to the search function -->
<% @zips.each do |zip| %>
<!--"link_to" creates a link...first param is what you want to "display"...the second parameter
is what you want to link to here it's a shortcut called "zip" (which passes the entrie POST and Rails will create the page with it's contents)
-->
<p><%= link_to zip.zip, zip %>|<%= zip.state %></p>
<hr />
<% end %>
<p><%= link_to "Add a New Zip", new_zip_path %></p>
但它不显示我输入的 zip 和状态......它显示这个(附图片)
这是日志的转储...
Started POST "/zips" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Processing by ZipsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"wP8eOqMzOjLfLZjmq62EXdO0C59fHyRk3C/Y4b+96mA=", "zip"=>{"zip"=>"91202", "state"=>"CA"}, "commit"=>"Add Zip Code"}
(0.3ms) BEGIN
SQL (0.7ms) INSERT INTO "zips" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", Sat, 03 Aug 2013 19:51:42 UTC +00:00], ["updated_at", Sat, 03 Aug 2013 19:51:42 UTC +00:00]]
(2.6ms) COMMIT
Redirected to http://chrish.sbx.4over.com:3000/zips
Completed 302 Found in 8ms (ActiveRecord: 3.6ms)
Started GET "/zips" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Processing by ZipsController#index as HTML
Zip Load (0.5ms) SELECT "zips".* FROM "zips"
Rendered zips/index.html.erb within layouts/application (2.7ms)
Completed 200 OK in 8ms (Views: 6.5ms | ActiveRecord: 0.5ms)
Started GET "/assets/application.css?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Started GET "/assets/zips.css?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Started GET "/assets/jquery.js?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Started GET "/assets/zips.js?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Started GET "/assets/turbolinks.js?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Started GET "/assets/jquery_ujs.js?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
Started GET "/assets/application.js?body=1" for 192.168.188.50 at 2013-08-03 12:51:42 -0700
:post 没有发送 POST 信息的任何原因?
我正在使用 Rails 4.0.0 和 Ruby 1.9.3p448:
[freedel@chrish.sbx.4over.com localdel]$ rails --version
Rails 4.0.0
[freedel@chrish.sbx.4over.com localdel]$ ruby --version
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]