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

  • Home
  • SEARCH
  • 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 4537228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:38:46+00:00 2026-05-21T14:38:46+00:00

I have this RoR snippet in a view: <%= link_to_unless(@posts_pages[:previous].nil?, Previous, blog_with_page_path(:page_num => @posts_pages[:previous]))

  • 0

I have this RoR snippet in a view:

<%= link_to_unless(@posts_pages[:previous].nil?, 
  "Previous", 
  blog_with_page_path(:page_num => @posts_pages[:previous])) %>

Here blog_with_page is a named route. The snippet works if @posts_pages[:previous].nil? is false (as expected) and the link is generated correctly. However, when @posts_pages[:previous].nil? is true, instead of simply getting the "Previous" string back, I get an error telling me that the route couldn’t be generated using :page_num=>nil. Is this the expected behavior? If the condition is met, the route code shouldn’t be evaluated, should it?
Here’s the complete error:
blog_with_page_url failed to generate from {:page_num=>nil, :action=>"show", :controller=>"pages"}, expected: {:action=>"show", :controller=>"pages"}, diff: {:page_num=>nil}

I’ve been looking at the link_to_unless code and I don’t understand why I get the error since it should be returning simply the name:

# File actionpack/lib/action_view/helpers/url_helper.rb, line 394
  def link_to_unless(condition, name, options = {}, html_options = {}, &block)
    if condition
      if block_given?
        block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
      else
        name
      end
    else
      link_to(name, options, html_options)
    end
  end

I’m using Rails 2.3.11 and Ruby 1.8.7

Cheers!

  • 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-21T14:38:47+00:00Added an answer on May 21, 2026 at 2:38 pm

    Because Ruby is not a lazy language, blog_with_page_path(:page_num => @posts_pages[:previous]) gets evaluated as soon as you call it, regardless of whether the value ever gets used by link_to_unless.

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

Sidebar

Related Questions

So I have this in my RoR app, it works in FF, Chrome, and
Here, I have a problem in searching record in Postgresql DB in RoR Application.
I have the following call in my RoR script: Foo.where(event = 'Login').group('user_id').order('user_id ASC').count() This
I have a game in RoR. The game breaks down like this. There are
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this line in a javascript block in a page: res = foo('<%=
I have this setup where in my development copy I can commit changes on
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the

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.