
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 0.94 KB | hits: 12 | expires: Never
Rails building multiple relationships in one form
undefined method `id' for #<Array:0x26abe70>
app/models/project.rb:35:in `pfollow!'
app/controllers/prelationships_controller.rb:6:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"NKqa1f0M2yPLQDHbRLnxl3SiwBeTus/1q1hpZjD7hgY=",
"prelationship"=>{"pfollower_id"=>["4",
"5"]},
"project_id"=>"90",
"commit"=>"Pfollow"}
class PrelationshipsController < ApplicationController
def create
@project = Project.find(params[:project_id])
@plant = Plant.find(params[:prelationship][:pfollower_id])
@project.pfollow!(@plant)
respond_to do |format|
format.html { redirect_to @project }
format.js
end
end
end
def pfollow!(pfollowed)
prelationships.create!(:pfollowed_id => pfollowed.id)
end
params[:prelationship][:pfollower_id].each do |p|
@project.pfollow!( Plant.find(p) )
end