Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 0.94 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Rails building multiple relationships in one form
  2. undefined method `id' for #<Array:0x26abe70>
  3. app/models/project.rb:35:in `pfollow!'
  4. app/controllers/prelationships_controller.rb:6:in `create'
  5. Request
  6.  
  7. Parameters:
  8.  
  9. {"utf8"=>"✓",
  10.   "authenticity_token"=>"NKqa1f0M2yPLQDHbRLnxl3SiwBeTus/1q1hpZjD7hgY=",
  11.   "prelationship"=>{"pfollower_id"=>["4",
  12.   "5"]},
  13.   "project_id"=>"90",
  14.   "commit"=>"Pfollow"}
  15.        
  16. class PrelationshipsController < ApplicationController
  17.  
  18.   def create          
  19.     @project = Project.find(params[:project_id])                                  
  20.     @plant = Plant.find(params[:prelationship][:pfollower_id])
  21.       @project.pfollow!(@plant)
  22.    respond_to do |format|
  23.      format.html { redirect_to @project }
  24.      format.js
  25.    end
  26.   end    
  27. end
  28.        
  29. def pfollow!(pfollowed)
  30.     prelationships.create!(:pfollowed_id => pfollowed.id)
  31.   end
  32.        
  33. params[:prelationship][:pfollower_id].each do |p|
  34.  @project.pfollow!( Plant.find(p) )
  35. end