-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
link_to_add_association compatibility with cells 4.0.2 #315
Comments
So if I understand correctly: you are using cells, you are using the cells folder-structure, so you need a different Just checking if it makes sense to be giving an extra parameter, or when using cells, we can always do |
Yes that is correct, I use link_to_add_association sometimes in cells and sometimes as it was designed to be used, though it seems to me a little more than just looking in the right place for the partial. The number of parameters is different, i.e from cells it is one ( a Hash) normally it is 2 ( partial name, Hash). I think, though I do not understand properly yet, that cells overwrites the global render with this other implementation. |
Closing this as it was suggested here trailblazer/cells#317 that it would be cleaner from me to overwrite the render method in Cells. |
@ryan2johnson9 I tried to solve that problem without monkey-patching any methods, so I thought if we have to include Cocoon helper into Cells manually, why don't we include dedicated helper? On my fork I have added Cocoon::CellsHelper, that includes mostly standard Cocoon::ViewHelper, only difference is render_association calls render_partial method now, which is different for both helpers. This way seems a little cleaner than both of your proposed solutions, and works well for me both in Cells and standard Rails views. Please correct me if I'm wrong 😃 |
@asaletnik Hey I tried your fix by monkeypatching the relevant methods in my cell. But we might want to use a partial in If we want to allow looking up files in EDIT It seems there's an issue with HTML escaping. Apparently the template of the data-attributes is inserted Escaped. This breaks everything.
|
@Startouf I reached the same point as you where the template was being unnecessarily HTML escaped. Although it's not the most elegant solution in the world, I was able to resolve that by adding an if cells_compatible
render(partial: partial, locals: partial_options).html_safe
else
render(partial, partial_options)
end As with any use of the |
Hi,
link_to_add_association is so good that I cannot do without it in my recent refactoring to the use of apotonick/cells
However it raised an error from within the Cocoon::ViewHelpers render_association method because it the render call was not compatible with rendering in cells.
I have written a monkey patch that works for me and I am wondering if you would like to support cells in your project. I will add my monkey patch and if you think it is worthwhile, I could make a pull request.
from within the cell, when you call link_to_add_association, pass in a render option
cells_compatible:true
like this:(note the leading underscore required in the partial_name)
in some model, or however you like to do monkey patches, (I use a class_extensions.rb file in my models directory) add this code:
This simply overwrites the same method in Coccon which looks like this
The text was updated successfully, but these errors were encountered: