I have two models:
Routes and Activity
I have a Many-To-Many relationship between them through a migration that looks like:
class ActivitiesRoutes < ActiveRecord::Migration
def up
create_table :activities_routes, :id => false do |t|
t.integer :route_id
t.integer :activity_id
end
end
end
In a rest service i get the data for a route and I get multiple activities, my models look like this:
class Route < ActiveRecord::Base
attr_accessible :activities_attributes
has_and_belongs_to_many :activities
accepts_nested_attributes_for :activities
end
and:
class Activity < ActiveRecord::Base
attr_accessible :activitytext, :iconid
has_and_belongs_to_many :routes
end
On my app controller I want to make something like :
ruta=Route.create({
#other data for the model
})
ruta.activities_attributes = @activitiesarray #Array made with the Activities received
But I get an error:
undefined method `activities_attributes' for #<Route:0x2bccf08>
If i left it like :
ruta.activities_attributes << @activitiesarray
I get:
undefined method `with_indifferent_access' for #<Activity:0x6af7400>
Does anyone know ho can I make that possible? Thank you :)