Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:38:23+00:00 2026-06-04T04:38:23+00:00

In the show action, there is logic that requires me to define: @object.nested_object.new (or

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:38:23+00:00Added an answer on June 4, 2026 at 4:38 am

    First you should not create a temporary object.

    if you follow the previous advice, simply do:

    @object.nested_objects.select(&:persisted?).each do |nested_objects|
      #display
    end
    

    This will filter objects from your db (no need to delete a temporary object, it will disappear at the end of the request).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new_story GET /story/new(.:format) {:action=>new, :controller=>stories} edit_story GET /story/edit(.:format) {:action=>edit, :controller=>stories} story GET /story(.:format) {:action=>show,
I notice that Windows XP Event Viewer show a list of typical actions under
I have an app that requires me to take an action after some period
I'm looking to make a show action of one of my controllers the root.
The standard way of creating URLs in grails is: <a href=${createLink(controller:'news', action: 'show', params:
I'm trying to show an extra menu item (contextual action bar) when the user
I can't get the Action Bar to display my action items. They all show
How can I get result from action? I need to show the commentID on
In my Rails controller I want to branch to a different controller's action, show
In my routes.rb I've got: map.connect ':name', :controller => 'my_classes', :action => 'show' And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.