Skip to content
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

Implement to_ary in Query #36

Merged
merged 1 commit into from
Nov 1, 2016
Merged

Conversation

mrcasals
Copy link
Contributor

I'm using rectify at https://github.com/codegram/decidim/pull/147 and I'm having problems trying to render the results of a query object in a view using both these methods:

render(participatory_processes)
<%= render partial: "promoted_process", collection: promoted_processes, as: :promoted_process %>

I'm getting this error:

#<Decidim::PublishedProcesses ...> is not an ActiveModel-compatible object. It must implement :to_partial_path

My first try was calling the query method on the query object in the view:

render(participatory_processes.query)

This didn't raise any error, but didn't render anything actually so it's not useful. Also, explicitly calling this method from the view feels weird.

Checking the Rails source code, Rails tries to check if the collection passed to the render method responds to to_ary. If it does not, it uses an empty array as the collection and thus it does not render anything (which is weird, actually):

https://github.com/rails/rails/blob/28a6571bae1d6bc1c774e8e501720374061a31f1/actionview/lib/action_view/renderer/partial_renderer.rb#L406

So my take is defining the to_ary method in the Query class as an alias from to_a. Both the unit tests and the tests I took on my app are green with this change.

@andypike andypike merged commit f3c948a into andypike:master Nov 1, 2016
@andypike
Copy link
Owner

andypike commented Nov 1, 2016

@mrcasals Thanks so much for the addition!! It's all merged and I'll cut a release for you now so you can update the gem in your project.

❤️ 💛 💙 💚 💜

@andypike
Copy link
Owner

andypike commented Nov 1, 2016

@mrcasals 0.7.1 is now release with your change 😄

@mrcasals
Copy link
Contributor Author

mrcasals commented Nov 2, 2016

Yay, thanks for the fast reply and for your work on rectify! Works awesomely! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants