Solidus: ActionView::Template::Error: no implicit conversion of nil into String

Created on 9 Jan 2016  路  9Comments  路  Source: solidusio/solidus

File "/app/vendor/bundle/ruby/2.2.0/gems/solidus_backend-1.1.1/app/views/spree/admin/products/index.html.erb", line 81, in block in _1a924487c5fe01e87250afd94d8aab9c

File "/app/vendor/bundle/ruby/2.2.0/gems/solidus_backend-1.1.1/app/views/spree/admin/products/index.html.erb", line 78, in _1a924487c5fe01e87250afd94d8aab9c

Most helpful comment

I found the fix for me. I was using the settings from spree for aws:

attachment_config = {

  s3_credentials: {
    access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    bucket:            ENV['S3_BUCKET_NAME']
  },

  storage:        :s3,
  s3_headers:     { "Cache-Control" => "max-age=31557600" },
  s3_protocol:    "https",
  bucket:         ENV['S3_BUCKET_NAME'],
  url:            ":s3_domain_url",

  styles: {
      mini:     "48x48>",
      small:    "100x100>",
      product:  "240x240>",
      large:    "600x600>"
  },

  path:           "/:class/:id/:style/:basename.:extension",
  default_url:    "/:class/:id/:style/:basename.:extension",
  default_style:  "product"
}

attachment_config.each do |key, value|
  Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end

The issue was the default_url. Its should be:

default_url: 'noimage/:style.png',

Now everything is working as expected.

All 9 comments

TypeError in Spree::Home#index
Showing /Users/alif/.gem/ruby/2.2.3/gems/solidus_frontend-1.1.1/app/views/spree/shared/_products.html.erb where line #31 raised:

no implicit conversion of nil into String

how can i add default image this is problem when i don't upload default photo ?

@saroar unfortunately this isn't enough information for us to understand or fix the problem, can you please post steps to recreate this on a fresh store?

yes i know what was the problem in spree was default image for every products but in Solidus don't have that features so when i am trying to post my products without image it give this error but if u upload image it work hope u will solve this bug in future :)

I have just created a new build of the following:

source 'https://rubygems.org'

ruby '2.3.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# Image uploding
gem 'paperclip'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'solidus'
gem 'solidus_auth_devise'
gem 'solidus_i18n', '~> 1.0'
gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize', branch: 'master'
gem 'solidus_product_description_editor', '~> 1.0', '>= 1.0.1'
gem 'solidus_social', '~> 1.0'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :production do
  # Heroku helper
  gem 'rails_12factor'
  # Image storage for heroku production
  gem 'aws-sdk', '< 2.0'

end

I have the same error:

Rendered /Users/barklem/.rvm/gems/ruby-2.3.1/gems/solidus_frontend-1.2.2/app/views/spree/home/index.html.erb within spree/layouts/spree_application (1400.3ms)
Completed 500 Internal Server Error in 1885ms (ActiveRecord: 79.1ms)

ActionView::Template::Error (no implicit conversion of nil into String):
    28:       <li id="product_<%= product.id %>" class="columns three <%= cycle("alpha", "secondary", "", "omega secondary", name: "classes") %>" data-hook="products_list_item" itemscope itemtype="http://schema.org/Product">
    29:         <% cache(@taxon.present? ? [I18n.locale, current_currency, @taxon, product] : [I18n.locale, current_currency, product]) do %>
    30:           <div class="product-image">
    31:             <%= link_to image_tag(product.display_image.attachment(:small), itemprop: "image"), url, itemprop: 'url' %>
    32:           </div>
    33:           <%= link_to truncate(product.name, length: 50), url, class: 'info', itemprop: "name", title: product.name %>
    34:           <span itemprop="offers" itemscope itemtype="http://schema.org/Offer">

This is your error if u read
no implicit conversion of nil into String
so find where this Nil came from ,ur which attributes are should be string and u getting nil so u can write if else statement when that attirbutes will be nil u convert it string hope this will help you

I found the fix for me. I was using the settings from spree for aws:

attachment_config = {

  s3_credentials: {
    access_key_id:     ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    bucket:            ENV['S3_BUCKET_NAME']
  },

  storage:        :s3,
  s3_headers:     { "Cache-Control" => "max-age=31557600" },
  s3_protocol:    "https",
  bucket:         ENV['S3_BUCKET_NAME'],
  url:            ":s3_domain_url",

  styles: {
      mini:     "48x48>",
      small:    "100x100>",
      product:  "240x240>",
      large:    "600x600>"
  },

  path:           "/:class/:id/:style/:basename.:extension",
  default_url:    "/:class/:id/:style/:basename.:extension",
  default_style:  "product"
}

attachment_config.each do |key, value|
  Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end

The issue was the default_url. Its should be:

default_url: 'noimage/:style.png',

Now everything is working as expected.

Thanks @chris-barklem , your comment just saved me a lot of time.

@chris-barklem Thank you so much! If you have the time, I'd really like to hear how you reached that conclusion and whether you (or anyone else) have any explanation for _why_ this was necessary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kennyadsl picture kennyadsl  路  3Comments

brchristian picture brchristian  路  4Comments

ericsaupe picture ericsaupe  路  4Comments

kennyadsl picture kennyadsl  路  3Comments

tudorpavel picture tudorpavel  路  3Comments