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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:26:34+00:00 2026-05-13T23:26:34+00:00

How do I fetch all ‘link’ entries exept those with an ‘url’ column that

  • 0

How do I fetch all ‘link’ entries exept those with an ‘url’ column that is blank? My controller looks like this:

  def show
    @user = User.find_by_username(params[:username])
    @links = @user.links.all

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @links }

    end
  end

Thanks in advance!

Edit #1

If I do:

@links = @user.all(:conditions => 'url != NULL')

I get a error:

NoMethodError in UsersController#show 
undefined method `all' for #<User:0x2254f98>

And if I do:

@links = @user.links.all(:conditions => 'url != NULL')

I still get all the links, even those with empty url fields…

Edit #2

If I do

@links = User.all(:conditions => 'url != NULL')

I get

ActiveRecord::StatementInvalid in UsersController#show
SQLite3::SQLException: no such column: url: SELECT * FROM "users" WHERE (url != NULL) 

And if I do

@links = Link.all(:conditions => 'url != NULL')

I still get all the links, even those with empty url fields…

I’m wondering if it’s a difference between NULL and the field beeing empty?

Edit #3

Now my code looks like this:

  def show
    @user = User.find_by_username(params[:username])
    @links = @user.links.all(:conditions => "url <> ''")

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @links }

    end
  end

Solution

#controller
@links = @user.links.not_null_url

#model
named_scope :not_null_url, :conditions => "url <> ''"

This works! Just be sure access the links with:

#view
<% @links.each do |link| %>

And not:

#view
<% @user.links.each do |link| %>
  • 1 1 Answer
  • 2 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-13T23:26:35+00:00Added an answer on May 13, 2026 at 11:26 pm

    its not @user, its

    User.all(:conditions => 'url != NULL')
    

    EDIT:

    Actually i have a doubt. Is "links" a column ins users table or is it a model?

    EDIT #2

    Thy this: @user.links.all(:conditions => {:url => !nil})

    EDIT #3

    Found it! url IS NOT NULL or URL != NULL or anything using NULL won’t solve your problem because, as you said, there’s a difference between a null and an empty field. The code below worked for me:

    @user.links.all(:conditions => "url <> ''")
    

    And as @klew suggested, it would be nicer if you use a named_scope:

    #model
    named_scope :not_null_url, :conditions => "url <> ''"
    
    #controller
    @user.links.not_null_url
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fetch some HTML from various blogs and have noticed that different
I would like to be able to fetch a web page's html and save
I want to fetch all the records of First_Name, LastName, First Name Last Name
I want to fetch all hits from lucene. Is there any wild card character
I need to fetch all the properties of an anonymous type which can be
I'm trying to fetch all expired objects for a model in my Django application.
I want to fetch all the option values(selected/unselected) in a selectbox on click of
I need to fetch all the rows where the 'zip' field is less than
I have to fetch all the files from a folder and i am using
How can i fetch all data from any table of a test DB 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.