A few days ago, I've had the same puzzle. :)
Try to change the *:tasks* to *:task_id*
<%= select :tasks, :label =>
"Tasks", :value_method=> :id, :text_method => :task_name, :collection
=> Task.all %>
^^^ => :task_id
On Mar 6, 12:19 am, zdenko <[email protected]> wrote:
> hi,
>
> I have two models with many to many associations:
>
> class Project
> include DataMapper::Resource
>
> property :id, Serial
> property :project_notes, Text
> property :project_name, String
> property :estimate, Integer
> property :project_code, String
>
> has n, :tasks, :through => Resource
> end
>
> class Task
> include DataMapper::Resource
>
> property :id, Serial
> property :hour_rate, Float
> property :task_name, String
> property :attr, Integer
>
> has n, :projects, :through => Resource
> end
>
> In the router.rb I have this:
> Merb::Router.prepare do
> resources :projects do |project|
> project.resources :tasks
> end
> ....
>
> For the association in the view I'm using a select control.
>
> <%= select :tasks, :label => "Tasks", :value_method
> => :id, :text_method => :task_name, :collection => Task.all %>
>
> And this is HTML code of the form:
> <form method="post" action="/projects/1">
> <input type="hidden" value="put" name="_method">
> <p>
> <label for="project_project_name">Project name</label><input
> type="text" class="text" value="test 1" name="project[project_name]"
> id="project_project_name">
> </p>
> <p>
> <label for="project_project_code">Project code</label><input
> type="text" class="text" value="t101" name="project[project_code]"
> id="project_project_code">
> </p>
> <p>
> <label for="project_project_notes">Notes</label>
> <textarea name="project[project_notes]"
> id="project_project_notes">
> </textarea>
> </p>
> <p>
> <label for="project_tasks">Tasks</label> <select name="project
> [tasks]" id="project_tasks">
> <option selected="selected" value="1">
> task 1
> </option>
> <option value="2">
> task 2
> </option>
> </select>
> </p>
> <p>
> <input type="submit" value="Update" name="submit" id="submit">
> </p>
> </form>
>
> When the model gets saved I get error:
> No Method Error 500
> undefined method `collection=' for "2":String
>
> Params: {"format"=>nil, "submit"=>"Update", "project"=>
> {"project_notes"=>"", "project_name"=>"test 1", "tasks"=>"4",
> "project_code"=>"dsds"}, "action"=>"update", "_method"=>"put",
> "id"=>"1", "controller"=>"projects"}
>
> I guess the actual problem is in incorrect naming of the select field.
> Could somebody point me in the right direction?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---