views:

36

answers:

2

Hello there,

I got followup tasks and notes. A note might have a followup task

So when im creating a task, it might bring task.note with a value or null

I getting some problems on retriving this note id

I'll post the log

<% task = task_item_new %>
<% n = Time.now.to_i %>


<div class="new_div" id= <%="task_item_#{n}"%>>
<% remote_form_for task, :url => { :controller => "tasks", :action => "create" } do |f|  %>
    <%= hidden_field_tag :elem_id, n %>
    <%= f.hidden_field :note, :value => task.note.id%>

    <div class="span-5"><%= f.collection_select :employee_id, @employees, :id, :name, :class => "inline_text" %></div>

    <div class="span-5"><%= f.text_field :description, :class => "inline_text" %></div>
    <div class="span-5"><%= f.datetime_select "due_date"  %></div>
    <div class="span-5">
      <%= f.submit 'Save' %> |
      <%= link_to_function "Cancel", "$(this).up('.new_div').remove(); $('flash_message').hide();"%>
    </div>    
<% end %>

</div>

The log:

Processing TasksController#create (for 127.0.0.1 at 2009-09-18 17:23:46) [POST]
  Parameters: {"commit"=>"Save", "action"=>"create", "authenticity_token"=>"wJ0gTPZQ6j3mY4d5D+YZr/UCsRyr6uGNiVu/Pi2UM+g=", "elem_id"=>"1253291024", "task"=>{"due_date(1i)"=>"2009", "due_date(2i)"=>"9", "due_date(3i)"=>"18", "due_date(4i)"=>"16", "employee_id"=>"60", "due_date(5i)"=>"23", "description"=>"test", "note"=>"98"}, "controller"=>"tasks"}

Task Columns (1.2ms)   SHOW FIELDS FROM `tasks`

ActiveRecord::AssociationTypeMismatch (Note(#19461770) expected, got String(#113650)):
app/controllers/tasks_controller.rb:97:in `new'
app/controllers/tasks_controller.rb:97:in `create'


As you can see note is being passed inside the task hash.

can't find the solution for this problem, i have this defined on the model

task model : has_one :note, :class_name => "Note", :foreign_key => "associated_note"

note model : belongs_to :task

(NOTE: task table got a column called associated_note )

Please help me on this issue

Thanks in advance

A: 
def create
    @task = Task.new(params[:task])
    @task.employee_id = params[:task][:employee_id]
    @task.creator_id = current_user.id



    respond_to do |format|
Yise
you should have edited your question. Please do so and remove your own answer
marcgg
A: 

I think that

<%= f.hidden_field :note, :value => task.note.id%>

should be

<%= f.hidden_field :note_id, :value => task.note.id%>
marcgg