views:

68

answers:

2

(rails 2.3) I have the following actions in the controller:

def new
  @entity = Entity.new
end

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

I have the following form:

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

For some reason the values for :title, and description is being passed as null. Everything else (e.g created_at, updated_at) gets populated.

Any suggestion why these values are being passed as null?

+1  A: 

Perhaps this might help:

ActionView::Helpers::PrototypeHelper

remote_form_for(record_or_name_or_array, *args, &proc;)

Creates a form that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement and a scope around a specific resource that is used as a base for questioning about values for the fields. Resource Example:

<% remote_form_for(@post) do |f| %>     ...
Mike Williamson
A: 

Maybe you can try to do this in your 'create' method:

def create
  Rails.logger.info "These are all params: " + params[:entity][:title] + params[:description]
  @entity = Entity.new(params[:entity])
  @entity.save
end
  • perhaps you can catch the problem in log

Also check Rails api for proper syntax - if you have generic form remote_form_for(@post) then it is ok, otherwise you need (:post).

Ki