ruby on rails - Activeadmin where to place this variable code from my view -


i have created nice little view has code in place in controller. have tried making controller model active admin ignores it. have tried small controller block inside active admin resource file caused errors. can place supply_company active admin controller can access it?

<% supply_company_id = supplycompany.find(params[:id])  @ccarray = companyscore.where(supply_company_id: supply_company_id).pluck(:score) %> 

the below partial works fine (yes know ugly) can seem find spot place logic rendered in activeadmin.

render partial

/app/views/admin/_supply_company_ratings.html.erb

<%    supply_company_id = supplycompany.find(params[:id])  @ccarray = companyscore.where(supply_company_id: supply_company_id).pluck(:score) %>   <% @ccarrayaverage = (@ccarray.inject 0, :+) / @ccarray.count%> <% @ccarraypercent = (@ccarrayaverage.to_f)/10*100 %> <% @divpercent = @ccarraypercent.to_s %>  average score   <h1> <%= @ccarrayaverage %></h1>   total score   <h1>  <%= @ccarray.inject 0, :+ %></h1>  total votes <h1> <%= @ccarray.count %> </h1>  percent <h1> <%= @ccarraypercent %> </h1>  <div class="progress">   <div class="progress-bar  progress-bar-custom" role="progressbar" aria-valuenow="<%=@divpercent%>"        aria-valuemin="0" aria-valuemax="100" style="width:<%=@divpercent%>%">     <%= @divpercent.to_s %>% percent   </div> </div> 

maybe because in sidebar not reading activeadmin controller block. /app/admin/supply_company.rb

   show title: :company_name      attributes_table        row :company_name       end      end     sidebar "products", only: :show     attributes_table_for supply_company       # row rating_for supplycompany, "price"         row  :company_name       row "ratings"           render  'supply_company_ratings'       end        row :products |pt|         pt.products.collect {|c| link_to c.product_name.capitalize, admin_products_path + "\/" + c.id.to_s}.join(", ").html_safe       end     end   end 

putting code aa controller block right idea.

controller   def index     supply_company_id = supplycompany.find(params[:id]).id # note .id part - makes sure pass id not whole object in query below     @ccarray = companyscore.where(supply_company_id: supply_company_id).pluck(:score)   end end 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -