I have an Article
, which has a nested resource of Image Gallery
. An Image Gallery
has a nested resource of Image Gallery Image
. I have set up my params for Articles
as such:
params.require(:article).permit(
:featured_image, :title, :description, :department_id, :order_number,
image_galleries_attributes: [:id, :order_number, :_destroy,
image_gallery_images_attributes: [:id, :order_number, :caption, :_destroy]
]
)
I am currently using the Cocoon Gem - and have tried to have a double nested resource within the form input, like so:
= f.fields_for :image_galleries do |gallery|
%h4 Image Gallery
= gallery.input :order_number, placeholder: "1"
= link_to_remove_association "Remove", gallery, class: "btn-remove"
= gallery.simple_fields_for :image_gallery_images do |image|
= render 'image_gallery_image_fields', image: image
= link_to_add_association 'add', gallery, :image_gallery_images
_image_gallery_image_fields.html.haml
= image.input :order_number
= link_to_remove_association "Remove", image
Even with having the local variables passed to the rendered view, I still get the following error:
undefined local variable or method `image'
Does a variable need to be passed differently when working with nested resources? Or is there any reason the automatically used template (_image_gallery_image_fields.html.haml) would need to be used differently?
Thanks for any available help!
UPDATE
Create method in Article Controller.
def create
@article = @issue.articles.create(article_params)
@article.user_id = current_user.id if current_user
@article.save
if @article.save
flash[:notice] = "Article was successfully created"
redirect_to edit_admin_issue_article_path(@issue, @article)
else
render 'new'
end
end