undefined local variable or method `form' for Class - ruby-on-rails

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.

Related

I am working on Ruby on rails but it is giving undefined method `errors' for nil:NilClass error

Don't know why my app is throwing error on the registration file.Plz let me know the error.Thank you very much
Error
Showing /home/punisher/Desktop/billboard/app/views/register/signup.html.erb where line #36 raised:
undefined method `errors' for nil:NilClass
Extracted source (around line #36):
<h1 class="Login-here">Register Here</h1>
<%= form_with model: #owner,url:register_path, local: true do |form| %>
<% if #owner.errors.any? %>
<div class="alert alert-danger">
<% #owner.errors.full_messages.each do |message| %>
<div> <%= message %> </div>
Register_controller
class RegisterController < ApplicationController
def new
#owner=Owner.new
end
def create
# render plain: "Thanks for registering!"
# render plain: params[:user]
#owner=Owner.new(owner_params)
if #owner.save
session[:owner_id] = #owner.id
redirect_to login_path
else
flash[:error] ="User Not Registered"
render :signup
end
end
private
def owner_params()
params.permit(:email, :company_name, :address, :contact_no, :password, :password_confirmation)
end
end
signup.erb.html
<body style = "background-color:rgb(92, 179, 196)">
<div class="tnavbar">
<div class="tlogo">
<%= image_tag('1.png', :class => "logoimg") %>
<h3 class="title"> Out of Home</h3>
</div>
<div>
<%= link_to "login", login_path, class:"home-btn"%>
</div>
</div>
<div class="container-fluid" style="margin-top:50px;">
<div class="row loginpagerow">
<div class="col-1">
</div>
<div class="logincol col-5 imagebox">
<h1 class="headinglogin">Bringing you the best of the best.</h1>
<%= image_tag('loginpageimage.png', :class => "img") %>
</div>
<div class="col-5 logincol loginbox">
<h1 class="Login-here">Register Here</h1>
<%= form_with model: #owner,url:register_path, local: true do |form| %>
<% if #owner.errors.any? %>
<div class="alert alert-danger">
<% #owner.errors.full_messages.each do |message| %>
<div> <%= message %> </div>
<% end %>
</div>
<% end %>
<div class="row" style="margin-top:30px">
<div style="width:45%; height:35vh; margin-left:25px;">
<%= form.email_field :email ,class: "form-control login-email-field signup-fields", placeholder:"Email" %>
<%= form.text_field :company_name ,class: "form-control login-email-field signup-fields", placeholder:"Company Name" %>
<%= form.text_field :address ,class: "form-control login-email-field signup-fields", placeholder:"Address" %>
</div>
<div style="width:45%; height:35vh; margin-left:25px;">
<%= form.telephone_field :contact_no ,class: "form-control login-email-field signup-fields", placeholder:"Contact No" %>
<%= form.password_field :password ,class: "form-control login-email-field signup-fields", placeholder:"password" %>
<%= form.password_field :password_confirmation,class: "form-control login-email-field signup-fields", placeholder:"Confirm password" %>
</div>
<div class="mb-3 login-input">
<%= form.submit "Signup" ,class: "sign-btn btn btn-primary"%>
</div>
</div>
<% end %>
</div>
<div class="col-1">
</div>
</div>
</div>
</body>
You have a app/views/register/signup.html.erb view and Rails expects signup method in your registrations_controller and is looking for #owner
instance method but you don't have signup method that's why it's raising an error because #owner is nil.
def signup
#owner = Owner.new(owner_params)
...
end

undefined local variable or method `cache_key_for_vendor_products'

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?

undefined method `strftime' for nil:NilClass - Comment Date

I am displaying the date when a comment is published:
<%= comment.created_at.strftime("%d %b %Y") %>
This works, except if the comment is not filled out correctly, and is submitted. If this occurs I get the error: undefined methodstrftime' for nil:NilClass` instead of my comment validations.
How to fix this, I am not sure?
Here's my code:
class CommentsController < ApplicationController
def create
#post = Post.friendly.find(params[:post_id])
#comment = #post.comments.create(params[:comment].permit(:name, `:email, :website, :body, :url))`
if #comment.errors.any?
render "posts/show"
else
redirect_to post_path(#post)
end
end
def destroy
#post = Post.friendly.find(params[:post_id])
#comment = #post.comments.find(params[:id])
#comment.destroy
redirect_to post_path(#post)
end
end
class Comment < ActiveRecord::Base
belongs_to :post
validates_format_of :email, :with => /#/
validates :name, presence: true, length: { minimum: 5}
validates :body, presence: true, length: { minimum: 5}
validates :body, presence: true, length: { minimum: 5}
def gravatar_url
stripped_email = email.strip
downcased_email = stripped_email.downcase
hash = Digest::MD5.hexdigest(downcased_email)
default_url = "https://s3-us-west-2.amazonaws.com/mirror-communications/assets/download.jpg"
"http://gravatar.com/avatar/#{hash}"
end
end
<!-- Post Comments Partial -->
<li>
<article class="comment">
<div class="user-avatar">
<%= image_tag comment.gravatar_url %>
</div>
<div class="comment-content">
<h5 class="name"><%= comment.name %></h5>
<div class="comment-meta comment-reply">
<span class="post-date"><%= comment.created_at.strftime("%d %b %Y") %></span>/<span class="comment-reply-link"><%= link_to comment.website.try(:remove, /.*\/\//), url_for(comment.website), target: '_blank', class: "comment-reply" %></span>
</div>
<p><%= comment.body %></p>
</div>
</article>
<!-- Form Partial -->
<%= form_for([#post, #post.comments.build]) do |f| %>
<% if #comment && #comment.errors.any? %>
<div id="error_explanation" class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h2><%= pluralize(#comment.errors.count, "error") %> Your comment could not be submitted:</h2>
<ul>
<% #comment.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<form class="comment-form">
<div class="row">
<div class="column width-4">
<%= f.text_field :name, class: "form-name form-element", placeholder: "Name*", :tabindex => 1 %>
</div>
<div class="column width-4">
<%= f.email_field :email, class: "form-email form-element", placeholder: "Email* (not displayed)", :tabindex => 3 %>
</div>
<div class="column width-4">
<%= f.url_field :website, class: "form-website form-element", placeholder: "Website", :tabindex => 4 %>
</div>
</div>
<div class="row">
<div class="column width-12">
<%= f.text_area :body, class: "form-message form-element", placeholder: "Message*", :tabindex => 5 %>
<%= f.submit class: "form-submit button medium bkg-black bkg-hover-turquoise color-white color-hover-white no-margin-bottom" %>
</div>
</div>
</form>
</div>
<% end %>
<!-- Posts Show -->`
<div class="post-comments">
<h3 class="comments-title">
<% if #post.comments.count < 2 %>
<%= #post.comments.count %> Comment</h3>
<% else %>
<%= #post.comments.count %> Comments</h3>
<% end %>
<div class="comments">
<ul class="comment-list">
<%= render #post.comments %>
</ul>
</div>
</div>
I think you have not populated local variable comment properly.
try this,
comment.created_at.strftime("%d %b %Y") if comment and comment.created_at

How to perform POST operation in Rails using AJAX

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.

Can't display all products

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

Resources