I'm working with three tables as follows:
class Article < ActiveRecord::Base
has_many :comentarios, :through => :comments
class Comment < ActiveRecord::Base
class Comentario < ActiveRecord::Base
ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection in ComentariosController#create
Cannot modify association 'Article#comentarios' because the source reflection class 'Comentario' is associated to 'Comment' via :has_many.
class ComentariosController < ApplicationController
@comentario = Comentario.new
@article = Article.find(params[:article_id])
@comentario = @article.comentarios.create(comentario_params)
Ok. The issue is that Rails is confused about which article to use here.
belongs_to :article but also your
belongs_to :article... so if you use
@article.commentarios - it's confused as to whether the article refers to the article of the comment or the article of the commentario.
You will probably need to update your form to be more explicit about what you're referring to. A form for the commentario should actually include fields for the comment it creates.
Somebody else had the same problem here. You may wish to look at the solution here: "Cannot modify association because the source reflection class is associated via :has_many"