2009-09-25 36 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| %>  ...