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 6613823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:15:51+00:00 2026-05-25T20:15:51+00:00

* warning – newbie alert * I’m reading a book called RailsSpace to learn

  • 0

* warning – newbie alert *

I’m reading a book called RailsSpace to learn Ruby on Rails framework. The author built user profiles which the user can edit, and now he’s building the public facing profiles based off the other user profiles. The only change he has to make is to basically hide the edit links on the public facing profile. He uses this function to hide it, but I don’t understand how it works…hide_edit_links is a variable

 # Return true if hiding the edit links for spec, FAQ, etc. 

    def hide_edit_links?

    not @hide_edit_links.nil? 

    end

He also writes

By the way, the reason hide_edit_links? works in general is that
instance variables are nil if not defined, so the function returns
false unless @hide_edit_links is set explicitly.

but I don’t really get it.

Can you explain in a bit more detail for a newbie?

He implements it later with this

<div class="sidebar_box"> <h2>
<% unless hide_edit_links? %> <span class="edit_link">
<%= link_to "(edit)", :controller => "faq", :action => "edit" %> </span>
<% end %>
  • 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-05-25T20:15:51+00:00Added an answer on May 25, 2026 at 8:15 pm

    I think the key to understand that code (I haven’t read the book) is that @hide_edit_links is not a boolean, it’s just some kind of tag. If @hide_edit_links is not nil ( it doesn’t matter which object type it’s) then hide_edit_links?` will return true.

    I have to say that the code is not at all straight forward, it’s definitely convoluted and complicated (probably without any reason)

    Example 1 (New instance, without @hide_edit_links set, so it shows link).

    • The class is instantiated (this code is not in the original question, but I assume it’s there), and since there’s not reference to @hide_edit_links, the value of the instace variable is nil
    • When hide_edit_links? is invoked from the page, @hide_edit_links is nil, so @hide_edit_links.nil? returns true, and thus not @hide_edit_links.nil? is false.
    • Since the page uses unless hide_edit_links?, it shows the link.

    Example 2 (New instance, with @hide_edit_links set with an object, so it doesn’t show the link).

    • The class is instantiated and @hide_edit_links is set to a value which is not nil.
    • When hide_edit_links? is invoked from the page, @hide_edit_links is not nil, so @hide_edit_links.nil? returns false, and thus not @hide_edit_links.nil? is true.
    • Since the page uses unless hide_edit_links?, it doesn’t show the link.

    Sorry about the trivial examples… the ‘feature’ is not complicated, but the solution used by the author looks terribly complicated to my dumb brain.

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

Sidebar

Related Questions

WARNING: Complete newbie to RoR and Ruby alert! * I have a login method
(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a
Warning I'm brand new to rails! While reading through a tutorial it has asked
Warning: I'm a Cocoa newbie. I'm reading Cocoa Programming For Mac OS X by
(Warning - asp newbie) I have an aspx file with the tag <%@ Page
!!! WARNING !!! Dearest SQL expert, please keep reading before to start to scream.
ld: warning: directory not found for option '-L/Users/MYcomputer002/Documents/MGTwitterEngineTest/yajl/build/yajl-1.0.7/lib' ld: framework not found Cocoa collect2:
Warning:Total Rails Newb (TRN). This should be a pretty basic question so I'm hoping
Warning. This is a total newbie question for Groovy.. I'm from a Java background
Warning: trying to learn OpenGL ... I have drawn a square with the following

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.