我对整个 ruby on rails 的东西还是很陌生,虽然我读过你可以轻松地执行 ajax 请求。我想要做的是在数据库表中添加一个新行,并从中传递一些变量。
我目前拥有的是
%li= link_to image_tag('trans.gif', :border => 0, :size => '16x16', :class => 'i-16-tick'), availabilities_path(:team_id => schedule.team_id, :user_id => current_user, :schedule_id => schedule.id), :remote => true, :method => :post, :title => 'Accept', :rel => 'tooltip-html'
控制器代码
`# POST /availabilities # POST /availabilities.json def create @availability = Availability.new(params[:availability])
respond_to do |format|
if @availability.save
format.html { redirect_to @availability, :notice => 'Availability was successfully created.' }
format.json { render :json => @availability, :status => :created, :location => @availability }
else
format.html { render :action => "new" }
format.json { render :json => @availability.errors, :status => :unprocessable_entity }
end
end
结束`
虽然它如何知道要传递给数据库的变量?
这就是目前正在发生的事情
Processing by AvailabilitiesController#create as HTML
Parameters: {"schedule_id"=>"18", "team_id"=>"1", "user_id"=>"38"}
User Load (1.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 38 LIMIT 1
(0.4ms) BEGIN
SQL (20.1ms) INSERT INTO "availabilities" ("available", "created_at", "schedule_id", "team_id", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["available", nil], ["created_at", Tue, 18 Sep 2012 23:07:26 EST +10:00], ["schedule_id", nil], ["team_id", nil], ["updated_at", Tue, 18 Sep 2012 23:07:26 EST +10:00], ["user_id", nil]]
(10.5ms) COMMIT