In the show action, there is logic that requires me to define:
@object.nested_object.new (or @object.nested_object.build or @object.nested_object.create)
However, when it’s time to show a list of the nested_objects using something like:
@object.nested_objects.each do |nested_objects|
#display
end
There is an extra line item for the temporary nested object created with @object.nested_object.new.
Is there a way to forcefully remove that temporary object before I display the list of the actual nested_objects?
Or is there another way of accomplishing the following:
-creating a temporary nested_object for logic tests
-showing a list of nested_objects
I’ve tried stuff like:
temp_nested_object = @object.nested_object.new
temp_nested_object.delete
but wasn’t successful.
Thanks for your time!
UPDATE:
I’m trying to accomplish this:
<% if can? :create, @project.tasks.build %>
From here:
https://github.com/ryanb/cancan/wiki/Nested-Resources
I’ve tried to find other ways of accomplishing this:
https://github.com/ryanb/cancan/issues/608
but seems like I need to workaround it in the view.
First you should not
createa temporary object.if you follow the previous advice, simply do:
This will filter objects from your db (no need to delete a temporary object, it will disappear at the end of the request).