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 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
  • 4 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

In few article it is mentioned that we should not fetch all column of
I want to fetch all the records that have null in openingbalance field of
i would like to know how to fetch all events from an EventStore using
Im trying to build a query that will fetch all changed rows from a
I want to use Linq to ADO.NET to fetch all rows that match the
When working with MySQL, how can I fetch all rows where the name column
Im building a Hibernate Criteria that will fetch all Appartments with a valid contract-date.
I am working in projects that need to fetch all information of single person
I want to write a Ruby program that will fetch all the unique http
The following code fetch all data (by clicking a.info link) from a php file

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.