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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:34:19+00:00 2026-06-09T12:34:19+00:00

Is it good to check db value in view, not in controller? Now i

  • 0

Is it good to check db value in view, not in controller?
Now i have such view:

- @articles.each do |art|
  -if art.QUANTITYM > 0
    =art.PRICEM
     %br
       = art.PRICEM * @currency.currencyvalue

On my previous rails 3.0.9 project (now 3.2.6), all was good, but now it gives me:

undefined method `>’ for nil:NilClass

Also my method in controller look’s like this:

def category
    @type_details = Type.find_by_TYP_ID(params[:type])
    @search_trees = SearchTree.find(:all, :include => [:designation], :conditions => { :STR_ID_PARENT => params[:cat]})


    @strlookup = StrLookup.find(:all, :conditions => { :STL_STR_ID => params[:cat]})
    @genart = GenericArticle.all(:conditions => { :GA_ID => @strlookup.map(&:STL_GA_ID)})

    @type = params[:type]
    @la_typs = LinkLaTyp.find(:all, :conditions => { :LAT_TYP_ID => params[:type], :LAT_GA_ID => @genart.map(&:GA_ID)})    


    data = "{ label : 1,  children : [{label : 1},{label : 1}]  }"
    #puts JSON.pretty_generate(data)


    if @genart.blank?
      @articles = nil

    else
      @linkla = LinkArt.find(:all, :conditions => { :LA_ID => @la_typs.map(&:LAT_LA_ID), :LA_GA_ID => @genart.map(&:GA_ID)})    
      @pre_articles = Article.find(:all, :include => [:supplier], :conditions => {:ART_ID => @linkla.map(&:LA_ART_ID)}, :order => "SUPPLIERS.SUP_BRAND, ARTICLES.QUANTITYM asc")
      @articles = Kaminari.paginate_array(@pre_articles).page(params[:page]).per(20)
    end


    @currency = Currency.find(:first)

    #@cart = current_cart #NOTE THIS!!!
    respond_to do |format|

      format.html # index.html.erb
      format.xml  { render :xml => @search_trees }
      #format.json { render :json => @search_trees }
    end
  end

How to check my db Quantity and in view accoding to value display price? Or it is “criminal”, and i must do this in controller? Than how to do this check in controller and display it in view?

Note, this is non-my db, so it’s very huge, and have a lot of tables, and data in them.

  • 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-09T12:34:20+00:00Added an answer on June 9, 2026 at 12:34 pm

    No problem checking it in the view. You get the error because art.QUANTITYM is nil. To prevent this error you have to check if it’s nil first and then if it’s bigger than zero:

    - if art.QUANTITYM.present? && art.QUANTITYM > 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, My English is not good, I have a View: <div class=editor-field id =
I'm not good in communicating between controllers, so i need to setup and check
(Let's assume that I have good reasons not to remove my NSAssert() checks in
Now, this is not strictly about URL shortening, but my purpose is such anyway,
Can a middleware check to see if a value is in the url, such
I have two view controllers. The CardWallet View Controller is my table view. Then
In every blog/article/Q&A I have read, nobody suggested to check the value returned by
What's a good way to check if a package is installed while within a
Our application is developed using Spring framework. Is it good practice to check null
Good morning, I have mysql queries where I would like to calculate percentage of

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.