Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck db value in rails view
    primarykey
    data
    text
    <p>Is it good to check db value in view, not in controller? Now i have such view:</p> <pre><code>- @articles.each do |art| -if art.QUANTITYM &gt; 0 =art.PRICEM %br = art.PRICEM * @currency.currencyvalue </code></pre> <p>On my previous rails 3.0.9 project (now 3.2.6), all was good, but now it gives me:</p> <blockquote> <p>undefined method `>' for nil:NilClass</p> </blockquote> <p>Also my method in controller look's like this:</p> <pre><code>def category @type_details = Type.find_by_TYP_ID(params[:type]) @search_trees = SearchTree.find(:all, :include =&gt; [:designation], :conditions =&gt; { :STR_ID_PARENT =&gt; params[:cat]}) @strlookup = StrLookup.find(:all, :conditions =&gt; { :STL_STR_ID =&gt; params[:cat]}) @genart = GenericArticle.all(:conditions =&gt; { :GA_ID =&gt; @strlookup.map(&amp;:STL_GA_ID)}) @type = params[:type] @la_typs = LinkLaTyp.find(:all, :conditions =&gt; { :LAT_TYP_ID =&gt; params[:type], :LAT_GA_ID =&gt; @genart.map(&amp;: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 =&gt; { :LA_ID =&gt; @la_typs.map(&amp;:LAT_LA_ID), :LA_GA_ID =&gt; @genart.map(&amp;:GA_ID)}) @pre_articles = Article.find(:all, :include =&gt; [:supplier], :conditions =&gt; {:ART_ID =&gt; @linkla.map(&amp;:LA_ART_ID)}, :order =&gt; "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 =&gt; @search_trees } #format.json { render :json =&gt; @search_trees } end end </code></pre> <p>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? </p> <p>Note, this is non-my db, so it's very huge, and have a lot of tables, and data in them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload