i'm working on a Rails application with Spree Commerce.
I'm trying to display all products in a taxon cause i'm using them not as category but as some kind of registry.
So, i'm editing /app/views/spree/taxons/show.html.erb. Especifically this line:
<%= render partial: 'spree/shared/products', locals: { products: #products, taxon: #taxon } %>
Changing it for:
<%= render :partial => 'spree/shared/products', :locals => { :products => #products } %>
But it still says "No products found". But in my index they are showed.
So, How can I properly show all products?
Thanks in advance.
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
Rails 4.2.5
Spree 3.0.4
As requested:
1) This is the show from products
<% #body_id = 'product-details' %>
<% cache [I18n.locale, current_currency, #product, #product.possible_promotions] do %>
<div data-hook="product_show" itemscope itemtype="https://schema.org/Product">
<div class="col-md-4" data-hook="product_left_part">
<div data-hook="product_left_part_wrap">
<div id="product-images" data-hook="product_images">
<div id="main-image" class="panel panel-default" data-hook>
<div class="panel-body text-center">
<%= render :partial => 'image' %>
</div>
</div>
<div id="thumbnails" data-hook>
<%= render :partial => 'thumbnails' %>
</div>
</div>
<div data-hook="product_properties">
<%= render :partial => 'properties' %>
</div>
<div data-hook="promotions">
<%= render :partial => 'promotions' %>
</div>
</div>
</div>
<div class="col-md-8" data-hook="product_right_part">
<div data-hook="product_right_part_wrap">
<div id="product-description" data-hook="product_description">
<h1 class="product-title" itemprop="name"><%= #product.name %></h1>
<div class="well" itemprop="description" data-hook="description">
<%= product_description(#product) rescue Spree.t(:product_has_no_description) %>
</div>
<div id="cart-form" data-hook="cart_form">
<%= render :partial => 'cart_form' %>
</div>
</div>
<%= render :partial => 'taxons' %>
</div>
</div>
</div>
<% end %>
2) Show from taxons
<h1 class="taxon-title"><%= #taxon.name %></h1>
<% content_for :sidebar do %>
<div data-hook="taxon_sidebar_navigation">
<%= render partial: 'spree/shared/taxonomies' %>
<%= render partial: 'spree/shared/filters' if #taxon.leaf? %>
</div>
<% end %>
<div data-hook="taxon_products">
<%= render partial: 'spree/shared/products', locals: { products: #products, taxon: #taxon } %>
</div>
<% unless params[:keywords].present? %>
<div data-hook="taxon_children">
<% cache [I18n.locale, #taxon] do %>
<%= render partial: 'taxon', collection: #taxon.children %>
<% end %>
</div>
<% end %>
3) This is how I render in my index
<div data-hook="homepage_products">
<% cache(cache_key_for_products) do %>
<%= render :partial => 'spree/shared/products', :locals => { :products => #products } %>
<% end %>
</div>
4) _products.html.erb
<%
paginated_products = #searcher.retrieve_products if params.key?(:keywords)
paginated_products ||= products
%>
<% content_for :head do %>
<% if paginated_products.respond_to?(:num_pages) %>
<%= rel_next_prev_link_tags paginated_products %>
<% end %>
<% end %>
<div data-hook="products_search_results_heading">
<% if products.empty? %>
<div data-hook="products_search_results_heading_no_results_found">
<%= Spree.t(:no_products_found) %>
</div>
<% elsif params.key?(:keywords) %>
<div data-hook="products_search_results_heading_results_found">
<h6 class="search-results-title"><%= Spree.t(:search_results, keywords: h(params[:keywords])) %></h6>
</div>
<% end %>
</div>
<% if products.any? %>
<div id="products" class="row" data-hook>
<% products.each do |product| %>
<% url = spree.product_url(product, taxon_id: #taxon.try(:id)) %>
<div id="product_<%= product.id %>" class="col-md-3 col-sm-6 product-list-item" data-hook="products_list_item" itemscope itemtype="https://schema.org/Product">
<div class="panel panel-default">
<% cache(#taxon.present? ? [I18n.locale, current_currency, #taxon, product] : [I18n.locale, current_currency, product]) do %>
<div class="panel-body text-center product-body">
<%= link_to small_image(product, itemprop: "image"), url, itemprop: 'url' %><br/>
<%= link_to truncate(product.name, length: 50), url, class: 'info', itemprop: "name", title: product.name %>
</div>
<div class="panel-footer text-center">
<span itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<span class="price selling lead" itemprop="price"><%= display_price(product) %></span>
</span>
</div>
<% end %>
</div>
</div>
<% end %>
<% reset_cycle("classes") %>
</div>
<% end %>
<% if paginated_products.respond_to?(:num_pages) %>
<%= paginate paginated_products, theme: 'twitter-bootstrap-3' %>
<% end %>
Controller index:
module Spree
class HomeController < Spree::StoreController
helper 'spree/products'
respond_to :html
def index
#searcher = build_searcher(params.merge(include_images: true))
#products = #searcher.retrieve_products
#taxonomies = Spree::Taxonomy.includes(root: :children)
end
end
end
Go to spree/frontend/app/controllers/spree/taxons_controller.rb
make the show method look like this
def show
#taxon = Taxon.friendly.find(params[:id])
return unless #taxon
#searcher = build_searcher(params.merge(include_images: true))
#products = #searcher.retrieve_products
#taxonomies = Spree::Taxonomy.includes(root: :children)
end
First of, your file should be called _products.html.erb.
But it still says "No products found"
Second, could you please show us this file?
But in my index they are showed.
Could you also show us how you render your products in your index?
EDIT: It seems like in Taxons#show, the #products instance variable is not set. Check if you set it in the show action in your TaxonsController.
Actually I am looking for an answer to "No products found"
Here is my question link:
Spree Commerce: No Products Found
Spree Commerce: No Products Found
I have just joined stackoverflow.com a couple of minutes, can't add a comment to above answers.
Here is /controllers/spree/taxons_controller.rb:
module Spree
class TaxonsController < Spree::StoreController
rescue_from ActiveRecord::RecordNotFound, with: :render_404
helper 'spree/products'
respond_to :html
def show
#taxon = Taxon.friendly.find(params[:id])
return unless #taxon
#searcher = build_searcher(params.merge(taxon: #taxon.id, include_images: true))
sorting_scope = params[:order].try(:to_sym) || :ascend_by_updated_at
#taxonomies = Spree::Taxonomy.includes(root: :children)
#searcher.retrieve_products
#products = #searcher.retrieve_products
#curr_page = params[:page] || 1
#products_per_page = Spree::Config.products_per_page
#start_no = #curr_page == 1 ? 1 : ((#curr_page.to_i-1)*#products_per_page)+1
#end_no = #products.length
if #curr_page.to_i > 1
#end_no = ( (#curr_page.to_i-1)*#products_per_page) + #end_no
end
# #end_no = #product_count <= #product_count ? #product_count : #products.length+(#curr_page.to_i-1)*#products_per_page
end
private
def accurate_title
#taxon.try(:seo_title) || super
end
end
end
Related
When I'm attempting to show a department view on my product#new page, this is my product#new page
<% #produto.errors.full_messages.each do |msg| %>
<div class="alert alert-danger" role="alert">
<%= msg %>
</div>
<% end %>
<%= form_for #produto do |produto| %>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<%= produto.label :nome %>
<%= produto.text_field :nome, class:"form-control" %>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<%= produto.label :descricao %>
<%= produto.text_area :descricao, class:"form-control", rows:"4" %>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<div class="form-group">
<%= form.label :departamento %>
<%= form.collection_select :departamento_id, #departamentos, :id, :nome, {}, class:"form-control" %>
</div>
</div>
</div>
<%= produto.submit "Criar",class:"btn btn-success" %>
<% end %>
This is my product_controller.rb
class ProdutosController < ApplicationController
def index
#produtos = Produto.order(nome: :asc).limit 5
#produtos_com_desconto = Produto.order(:preco).limit 1
end
def new
#produto = Produto.new
#departamentos = Departamento.all
end
def create
valores_produto = params.require(:produto).permit(:nome, :descricao, :preco, :quantidade)
#produto = Produto.new valores_produto
#Produto.create valores_produto
if #produto.save
flash[:notice] = "Produto criado com sucesso!"
redirect_to root_url
else
render :new
end
end
def destroy
id = params[:id]
Produto.destroy id
redirect_to root_url
end
def search
#nome = params[:nome]
#produtos = Produto.where "nome like ?", "%#{#nome}%"
end
end
So, when i'm trying to access my product/new page , i'm receiving the error NameError in Produtos#new: undefined local variable or method `form' for #<#<Class.
<%= form.label :departamento %> is looking for the form variable but there is none defined. Instead <%= form_for #produto do |produto| %> has defined producto and uses it as <%= produto.label :nome %>. So you probably want <%= producto.label :departamento %>
Note the variable should probably be form. The variable is a FormBuilder, not a Produto. Calling it producto is confusing.
I've installed the Spree Multi-Vendor gem and have built my Vendor Show page, but am getting a NameError message from the cache_key_for_vendor_products line. Here is my Vendor Controller
module Spree
class VendorsController < Spree::StoreController
before_action :load_taxon, only: :show
def index
#vendors = Spree::Vendor.active
end
def show
#vendor = Spree::Vendor.active.friendly.find(params[:id])
#searcher = build_searcher(searcher_params)
#products = #searcher.retrieve_products.where(vendor_id: #vendor.id)
end
private
def load_taxon
#taxon ||= Spree::Taxon.friendly.find(params[:taxon_id]) if params[:taxon_id].present?
end
def searcher_params
searcher_params = params.merge(include_images: true)
searcher_params[:taxon] = load_taxon.id if load_taxon.present?
searcher_params
end
def vendor_params
params.require(:spree_vendor).permit(
*Spree::PermittedAttributes.vendor_attributes,
stock_locations_attributes: Spree::PermittedAttributes.stock_location_attributes
)
end
def vendor_user_params
params.require(:spree_vendor).require(:user).permit(Spree::PermittedAttributes.user_attributes)
end
def vendor_stock_location_params
params.require(:spree_vendor).require(:stock_location).permit(Spree::PermittedAttributes.stock_location_attributes)
end
end
end
My Vendor Show
<% description = simple_format(#vendor.about_us, class: 'mb-0') %>
<% short = truncate(description, separator: ' ', length: 200, escape: false) %>
<div class="container">
<div class="row px-lg-3 mt-3 vendor-details">
<div class="col-12 text-uppercase text-center mt-4 mb-5 mb-sm-4">
<h1 class="mt-2 mb-4"><%= #vendor.name %></h1>
</div>
<div class="col-12 col-sm-6 col-lg-5 text-center pt-sm-4 pt-lg-3 pb-sm-5 vendor-details-image">
<% if #vendor.image.present? %>
<%= image_tag main_app.url_for(#vendor.image.attachment), class: 'mw-100' %>
<% end %>
</div>
<div class="col-12 col-sm-6 col-lg-5 offset-lg-1 mt-5 mt-sm-0 d-flex flex-column justify-content-center vendor-description">
<div class="vendor-details-about">
<% if description == short %>
<%= description %>
<% else %>
<div class="js-readMore">
<%= tag.div class: "js-readMore-short" do %>
<%= short %>
<% end %>
<%= tag.div class: "js-readMore-full d-none" do %>
<%= description %>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
<p><%= #vendor.contact_us %></p>
<hr/>
<div class="row">
<div class="col-12 mt-5 vendor-details-products">
<% cache(cache_key_for_vendor_products) do %>
<%= render template: #taxon ? 'spree/taxons/show' : 'spree/products/index' %>
<% end %>
</div>
</div>
</div>
And Multi Vendor Helpers located in lib/spree_multi_vendor/multi_vendor_helpers.rb
module SpreeMultiVendor
module MultiVendorHelpers
include ::Spree::ProductsHelper
include ::Spree::FrontendHelper
def cache_key_for_vendor_products
count = #products.count
max_updated_at = (#products.maximum(:updated_at) || Date.today).to_s(:number)
products_cache_keys = "spree/vendor-#{#vendor.slug}/products/all-#{params[:page]}-#{params[:sort_by]}-#{max_updated_at}-#{count}"
(common_product_cache_keys + [products_cache_keys]).compact.join('/')
end
end
end
I've gotten these codes here: https://github.com/spree-contrib/spree_multi_vendor/pull/120/files
On my vendor show page, I get this error and I can't for the life of me figure out what went wrong:
NameError in Spree::Vendors#show
undefined local variable or method `cache_key_for_vendor_products' for #<#Class:0x00007fc173a88478:0x00007fc176034b40>
Can any of you help?
I have two tabs at the profile page: tab 1) my recipes, tab 2) my favorites.
Kaminari pagination works just fine when I go to the index page for recipes. However the pagination does not work properly at the profile page. When I click on next it does show me the next page, but the pagination bar disappears. So I cannot go back, unless I refresh the page.
Who can help me? Thank you in advance.
Profile controller:
class ProfilesController < ApplicationController
def show
#recipes = current_user.recipes.order("name").page(params[:recipes_page]).per(3)
#favorites = current_user.favorites.order("name").page(params[:favorites_page]).per(3)
end
end
Kaminari:
<% if #recipes.present? %>
<div class="apple_pagination" id="paginator-my-recipes">
<%= paginate #recipes, :remote => true, :param_name => :recipes_page %>
</div>
<% end %>
app/views/profiles/show.html.erb:
<div class="container is-small sand-color">
<div class="tabs">
<div class="your-recipes-btn">
<a class= "tab active" data-target= "#your-recipes">
<h4>Your recipes</h4>
</a>
</div>
<div class="your-favorites-btn">
<a class= "tab" data-target= "#your-favo">
<h4>Favorites</h4>
</a>
</div>
</div>
</div>
<div class="tab-content" id="your-recipes">
<div class="container is-small sand-color">
<% if #recipes.present? %>
<%= render #recipes %>
<% else %>
<h4 class="text-center">Create your own recipes</h4>
<% end %>
</div>
<% if #recipes.present? %>
<div class="apple_pagination" id="paginator-my-recipes">
<%= paginate #recipes, :remote => true, :param_name => :recipes_page %>
</div>
<% end %>
</div>
<div class="tab-content hidden" id="your-favo">
<div class="container is-small sand-color">
<% if #favorites.present? %>
<%= render #favorites %>
<% else %>
<h4 class="text-center">You don't have any recipes</h4>
<% end %>
</div>
<% if #favorites.present? %>
<div class="apple_pagination" id="paginator-my-favo">
<%= paginate #favorites, :remote => true, :param_name => :favorites_page %>
</div>
<% end %>
</div>
app/views/profiles/_favorites.html.erb
<div class="product">
<div class='product-upvote'>
<div class="product-arrow"></div>
<div class='product-count'>95</div>
</div>
<% if recipe.photo != nil %>
<%= cl_image_tag recipe.photo, height: 100, width: 150, crop: :fill, class: "product-image hidden-xs" %>
<% else %>
<% end %>
<div class='product-body'>
<%= link_to recipe_path(recipe) do %>
<h4><%= recipe.name %></h4>
<% end %>
<div class="summary dont-break-out">
<p><%= recipe.summary %></p>
</div>
<div class="recipes-info">
<div class="recipes-kitchen">
<p>Gang</p>
<h5> <%= recipe.course %> </h5>
</div>
<div class="recipes-kitchen">
<p>Keuken</p>
<h5> <%= recipe.kitchen %> </h5>
</div>
<div class="cooking-time">
<p>Kooktijd</p>
<h5><%= recipe.cooking_time %> min</h5>
</div>
<div class="created">
<p>Geplaatst op</p>
<h5><%= recipe.created_at.strftime('%d/%m/%Y') %> </h5>
</div>
</div>
</div>
</div>
app/views/profiles/show.js.erb:
$('#your-recipes').html('<%= escape_javascript render(#recipes) %>');
$('#paginator-my-recipes').html('<%= escape_javascript(paginate(#recipes, :remote => true).to_s) %>');
$('#your-favo').html('<%= escape_javascript render(#favorites) %>');
$('#paginator-my-favo').html('<%= escape_javascript(paginate(#favorites, :remote => true).to_s) %>');
Scenario
I have created a simple application for learning Rails and Bootstrap. What this application does is it allows users to give nicknames to celebrities and like the nicknames as well. You can check it at http://celebnicknames.herokuapp.com
I have got a link_to button for posting likes for a celebrity in my home/index.html.erb as:
<%= link_to home_updatelike_path(id: nickname.id, search: #search ), method: :post, remote: true, class: "update_like btn btn-xs btn3d pull-right" do %>
<i class="glyphicon glyphicon-thumbs-up"></i>
<% end %>
The corresponding code in my home_controller.rb for the post method is:
def updatelike
#like = Like.new(:nickname_id => params[:id], :ip_address => request.remote_ip)
#like.save
respond_to do |format|
format.html { redirect_to root_path("utf8"=>"✓", "search"=>params[:search], "commit"=>"Search") }
format.json { head :no_content }
format.js { render :layout => false }
end
end
The code in my updatelike.js.erb is as:
$('.update_like').bind('ajax:success', function() {
});
Now, what I want to achieve is to submit a like without performing a page reload.
Problem:
Whenever I press the button, the database operation is done, but the change is not reflected in the page unless I reload it. Please guide me through this noob question and also provide links to resources which explain using AJAX with Rails.
Edit
Here is the entire home/index.html.erb
<div class="jumbotron col-md-6 col-md-offset-3">
<h1 class='text-center'>Nicknamer</h1>
</div>
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 bottom50">
<%= form_tag(root_path, :method => "get", id: "search-form", type: "search") do %>
<div class = "form-group" >
<div class = "col-sm-9 " >
<%= text_field_tag :search, params[:search], placeholder: "Name", class: "form-control" %>
</div>
<div class = "col-sm-3" >
<%= submit_tag "Search", class: "btn btn-default btn-block btn-success"%>
</div>
</div>
<% end %>
</div>
</div>
<% #names.each do |name| %>
<div class="col-md-6 col-xs-8 col-md-offset-3 col-xs-offset-2 bottom50">
<!-- ===== vCard Navigation ===== -->
<div class="row w">
<div class="col-md-4">
<% if name.sex == true %>
<%= image_tag("mal.jpg", :alt => "", class: "img-responsive") %>
<% else %>
<%= image_tag("fem.jpg", :alt => "", class: "img-responsive") %>
<% end %>
</div><!-- col-md-4 -->
<!-- ===== vCard Content ===== -->
<div class="col-md-8">
<div class="row w1">
<div class="col-xs-10 col-xs-offset-1">
<h3><%= "#{name.name}" %></h3>
<hr>
<h5>Also known as</h5>
<% name.nicknames.each do |nickname| %>
<div class = "row w2 bottom10">
<% if nickname.name_id == name.id %>
<div class="col-xs-7">
<%= nickname.nickname %>
</div>
<div class="col-xs-3 text-right">
<%= pluralize(nickname.likes.count, 'like') %>
</div>
<div class="col-xs-1">
<%= link_to home_updatelike_path(id: nickname.id, search: #search ), method: :post, remote: true, class: "update_like btn btn-xs btn3d pull-right" do %>
<i class="glyphicon glyphicon-thumbs-up"></i>
<% end %>
</div>
<% end %><!-- if -->
</div><!-- row w2 -->
<% end %><!-- do -->
<div class = "row w3 bottom30">
<%= form_for #addnickname, as: :addnickname, url: {action: "addnickname"} do |f| %>
<div class = "form-group" >
<%= f.hidden_field :name_id, :value => name.id %>
<%= f.hidden_field :search, :value => #search %>
<div class = "col-xs-9">
<%= f.text_field :nickname , :required => true, class: "form-control" %>
</div>
<div class = "col-xs-3">
<%= f.submit "Add", class: "btn btn-default btn-info"%>
</div>
</div>
<% end %>
</div>
</div><!-- col-xs-10 -->
</div><!-- row w1 -->
</div><!-- col-md-8 -->
</div><!-- row w -->
</div><!-- col-lg-6 -->
<% end %>
</div><!-- /.container -->
and this is the entire home_controller.rb
class HomeController < ApplicationController
def index
#addnickname = Nickname.new
if params[:search]
#search = params[:search]
#names = Name.search(params[:search])
else
#names = Name.all
end
end
def addnickname
#addnickname = Nickname.new(:nickname => params[:addnickname][:nickname], :name_id => params[:addnickname][:name_id])
if #addnickname.save
redirect_to root_path("utf8"=>"✓", "search"=>params[:addnickname][:search], "commit"=>"Search")
else
render :new
end
end
def updatelike
#like = Like.new(:nickname_id => params[:id], :ip_address => request.remote_ip)
#like.save
respond_to do |format|
format.html { redirect_to root_path("utf8"=>"✓", "search"=>params[:search], "commit"=>"Search") }
format.json { head :no_content }
format.js { render :layout => false }
end
end
private
def addnickname_params
params.require(:addnickname).permit(:name_id, :nickname, :search)
end
end
Ok, so you need a way to identify the div with the number that needs to change:
<div class="col-xs-3 text-right">
<%= pluralize(nickname.likes.count, 'like') %>
</div>
The easiest way to do this would be to have an id attribute on the div that corresponds to the (unique) database id of the nickname. Rails has a helper method for this called div_for. So you could change the above code to this:
<%= div_for(nickname, class: "col-xs-3 text-right") do %>
<%= pluralize(nickname.likes.count, 'like') %>
<% end %>
That will generate a div with an id like nickname_1 (if this id of the nickname is 1).
Now in your javascript template you can easily target the div that needs to be updated:
$("nickname_#{#like.nickname.id}").html(#like.nickname.likes.count);
The ajax:success binding is unnecessary here since you are rendering a javascript template. In the template you can access instance variables set in the controller - just like you can from an HTML template. The above code is meant to replace the content of the div that contains the likes count with the new count.
I have the following Code on a partial that dynamically generates a list of associated steps to a pin. Both pins and steps have image(s). Users are able to add multiple steps to a pin and then this view dynamically generates a view of these steps. For each step there are associated image(s) which I'd like to pop-up as a modal. The challenge is I keep getting the following error:
"undefined local variable or method `step' for #<#:0x00000102f498d8>"
When I stub out rendering the partial, the modal appears basically blank but works. Any ideas How do I do this?
<div class="col-md-6">
<% (0..(Step.where("pin_id = ?", params[:id]).count)-1).each do |step| %>
<div class="col-md-12">
<div class="well">
<ul class="nav pull-right">
<% if current_user == #pin.user %>
<%= link_to edit_step_path((Step.where("pin_id = ?", params[:id]).fetch(step)), :pin_id => #pin.id) do %>
<span class="glyphicon glyphicon-edit"></span>
Edit
<% end %> |
<%= link_to Step.where("pin_id = ?", params[:id]).fetch(step), method: :delete, data: { confirm: 'Are you sure?' } do %>
<span class="glyphicon glyphicon-trash"></span>
Delete
<% end %> |
<%= link_to new_step_image_path(:step_id => Step.where("pin_id = ?", params[:id]).fetch(step), :pin_id => #pin.id) do %>
Add
<span class="glyphicon glyphicon-picture"></span>
<% end %>
<% end %>
<% if StepImage.where("step_id = ?", Step.where("pin_id = ?", params[:id]).pluck(:id).fetch(step)).count == 0 %>
<% else %>
| <a href="#StepImageModal" data-toggle="modal">
<span class="glyphicon glyphicon-picture"></span> (<%= StepImage.where("step_id = ?", Step.where("pin_id = ?", params[:id]).pluck(:id).fetch(step)).count %> ) </strong>
</a>
<% end %>
</ul>
<strong> Step <%= step+1 %>
<p>
<%= Step.where("pin_id = ?", params[:id]).pluck(:description).fetch(step) %>
</p>
</div>
</div>
<%end %>
</div>
<div class="modal fade" id="StepImageModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal Header</h3>
</div>
<div class="modal-body">
<%= render :partial => 'pins/step_images',
:locals => { :step => step } %>
</div>
<div class="modal-footer">
Close
</div>
</div>
I don't get what you're trying to do here
Loop
As mentioned in the comments, you've got a loop which goes through your steps. However, outside the loop, you want to display the partial
The solution to your woes will either be to set an instance variable (not desired), or use another persistent data type. I'd do this:
#app/controllers/steps_controller.rb
def action
#step = {}
end
#app/views/steps/action.html.erb
<% (0..(Step.where("pin_id = ?", params[:id]).count)-1).each do |step| %>
<% #step[step.id.to_sym] = step.details %>
<% end %>
<%= render :partial => 'pins/step_images', :locals => { :step => #step } %>
unless
Some refactoring for you:
<% unless StepImage.where("step_id = ?", Step.where("pin_id = ?", params[:id]).pluck(:id).fetch(step)).count == 0 %>
| <%= link_to "#StepImageModal", data: { toggle: "modal"} do %>
<span class="glyphicon glyphicon-picture"></span>(<%= StepImage.where("step_id = ?", Step.where("pin_id = ?", params[:id]).pluck(:id).fetch(step)).count %> ) </strong>
<% end %>
<% end %>