【问题标题】:pass the class name in view (rails)在视图中传递类名(rails)
【发布时间】:2016-01-08 17:44:40
【问题描述】:

在视图传递变量@stalytd:

<%= render :partial => "shared/table", :locals => {:@number => "10 этаж", :@apartmentq => @apartment10, :apartment => @apartment, :stalytd =>@stalytd} %>

如何使用它为部分、类中的变量名赋值?

<table id="tabletd" class="@stalytd">

我需要将填充了客户数据的单元格涂成红色。

@fio=apartment.f_buyer
    @ifo=apartment.i_buyer

    if @fio != nil 
        elsif @ifo != ""
    then 
        @stalytd=redcolor
    else
        @stalytd=greencolor
   end 

【问题讨论】:

  • 不知道怎么弄(

标签: ruby-on-rails class view


【解决方案1】:

像这样使用你的变量:-

<%= @stalytd =%>

例如

<table id="tabletd" class="<%= @stalytd =%>">

【讨论】:

    【解决方案2】:
    <table id="tabletd" class="<%= @stalytd %>">
    

    【讨论】:

      【解决方案3】:

      试试这个:

      <table id="tabletd" class="<%=stalytd %>">
      

      【讨论】:

      • 分配的是 class="@stalytd",而不是值
      • 抱歉,在您的partial 中,应该是class="&lt;%=stalytd %&gt;" 没有“@”
      猜你喜欢
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      相关资源
      最近更新 更多