2009-09-25 35 views
0

(軌道2.3) 我在控制器執行以下操作:form_remote_for傳遞空值

def new 
    @entity = Entity.new 
end 

def create 
    @entity = Entity.new(params[:entity]) 
    @entity.save 
end 

我有以下形式:

#this is the new.html.erb 
<% for_remote_for(@entity) do |f| %> 
<%= f.text_field :title %> 
<%= f.text_field :description %> 
<% end %> 

出於某種原因值:標題,並且描述被傳遞爲null。其他所有內容(例如created_at,updated_at)都會被填充。

任何建議爲什麼這些值被傳遞爲null?

回答

0

也許你可以嘗試做這在 '創造' 的方法:

def create 
    Rails.logger.info "These are all params: " + params[:entity][:title] + params[:description] 
    @entity = Entity.new(params[:entity]) 
    @entity.save 
end 
  • 或許你可以在日誌中捕捉問題

而且檢查Rails api的正確語法 - 如果你有一般形式remote_form_for(@post)那麼它是好的,否則你需要(:post)

1

或許這可能幫助:

::的ActionView ::助手PrototypeHelper

remote_form_for(record_or_name_or_array, *args, &proc;) 

創建一個表單,會在後臺,而不是常規重裝崗位設置和周圍的作用域提交使用XMLHttpRequest的特定的資源被用作詢問字段值的基礎。 資源 例子:

<% remote_form_for(@post) do |f| %>  ...