(对不起,我的英语) 如果我想上传一个新的纪录,:name
和:date
PARAMS,那是什么,我发现:回报率:.create尼尔斯
控制器:
class ActorController < ApplicationController
def index
end
def new
@actor = Actors.create
end
def create
@actor = Actors.create(params[:actors])
if @actor.save
redirect_to actor_path, :notice => "Your actor was saved."
else
render "new"
end
end
end
型号:(actors.rb)
class Actors < ActiveRecord::Base
attr_accessible :birth, :name
end
和视图:(new.html.erb)
<%= form_for(@actor) do |a| %>
<%= a.text_field :name %>
<%= a.text_field :birth %>
<%= a.submit %>
<% end %>
而我在本地服务器控制台输出为:
Started PUT "/actor/40" for 127.0.0.1 at 2013-03-27 13:38:15 +0100
Processing by ActorController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BKhrP1Rfkco7r05wPT758M3CHQXRP5l5jcul77oTLPw=", "actors"=>{"name"=>"Bunny", "birth"=>"19/21/21"}, "commit"=>"Update Actors", "id"=>"40"}
(1.2ms) begin transaction
SQL (0.7ms) INSERT INTO "actors" ("birth", "created_at", "name", "updated_at") VALUES (?, ?, ?, ?) [["birth", nil], ["created_at", Wed, 27 Mar 2013 12:38:15 UTC +00:00], ["name", nil], ["updated_at", Wed, 27 Mar 2013 12:38:15 UTC +00:00]]
(197.8ms) commit transaction
(0.2ms) begin transaction
(0.1ms) commit transaction
Redirected to http://localhost:3000/actor/40
Completed 302 Found in 209ms (ActiveRecord: 200.0ms)
末-1但 当我解决它之后,它使另一个错误: 未初始化的常数ActorController :: Actor – 2013-03-27 12:51:22
查看我的更新回答。在控制器中它应该是复数。所以,'ActorsController :: ApplicationController' – Vinay 2013-03-27 12:53:52
期望/home/ben/blog/app/controllers/actor_controller.rb来定义ActorController – 2013-03-27 12:58:06