Spree deface override tutorial - ruby-on-rails

I am following the Spree deface overrides developer guide: http://guides.spreecommerce.com/developer/deface_overrides_tutorial.html
My code matches their's exactly, but I keep getting this error. I looked all around but I didn't see anyone else having this problem or anything similar at all:
undefined method `content_tag' for Spree:Module
I am running Rails 4.0.2 and ruby 1.9.3 (it's possible that the tutorial wasn't updated for rails 4?)
here's my code:
app/overrides/add_sale_price_to_product_edit.rb
Deface::Override.new(:virtual_path => 'spree/admin/products/_form',
:name => 'add_sale_price_to_product_edit',
:insert_after => "erb[loud]:contains('text_field :price')",
:text => "
<%= f.field_container :sale_price do %>
<%= f.label :sale_price, raw(Spree.t(:sale_price)) %><span>*</span>
<%= f.text_field :sale_price, :value =>
number_to_currency(#product.sale_price, :unit => '') %>
<%= f.error_message_on :sale_price %>
<% end %>
")
app/models/spree/product_decorator.rb
module Spree
Product.class_eval do
delegate_belongs_to :master, :sale_price
end
end

You're getting the error because the translation for Spree.t(:sale_price) is not specified. This is failing because Rails 4.0.2 made some changes to the I18n API . You have a few choices.
Add a translation for the missing tag and remember that this content_tag issue is caused by this crazy bug.
Downgrade to Rails 4.0.0 (not recommended)
Upgrade spree to the 2-1-stable branch (or wait until 2.1.4 is released)
Apply this change to your local Spree installation. It should correct this issue.
Any of those should get you working again.

Related

Wice_Grid CSV export not working - Uninitialized constant CSV::Writer

I "inherited" a rails aplication running with ruby 1.8.7 in development.
I have a wice_grid table which I'm trying to export in CSV and in development all goes perfect.
When I push it to production, i get the following error:
uninitialized constant CSV::Writer
The production machine is running Ruby 1.9.1 and from what I read, I suppose the problem comes from there.
I've tried to put:
required 'csv'
In the controller or the model, but nothing happens, development works, production does not.
Here is the controller code:
def index
require 'csv'
#service_requests = initialize_grid(ServiceRequest,
:name => "solicitudes",
:order => "created_at" ,
:order_direction => 'desc',
:include => [:user, :service],
:enable_export_to_csv => true,
:csv_file_name => 'Listado de Solicitudes'
)
export_grid_if_requested('solicitudes' => 'service_requests') do
#Si se pulsa en exportar se exportan todos las celdas de la tabla seleccionada (con filtros aplicados)
end
end
Here is the part of the view, which calls a partial:
<%= render :partial => 'service_requests' %>
Here is the partial, cropped for making the question not too long:
<%= grid(#service_requests, :show_filters => :always) do |service_request|
[...]
service_request.column :column_name => 'Nombre' , :attribute_name => 'name', :model_class => User do |sr|
sr.user.name
end
service_request.column :column_name => 'Apellidos' , :attribute_name => 'lastName' , :model_class => User do |sr|
sr.user.lastName
end
[...]
end %>
I read this thread but didnt help me much: write csv in ruby 1.9 and CSV::Writer
Thank you all in advance!
Somewhere, that you haven't posted, you are referencing CSV::Writer. This works locally because you're using Ruby 1.8.7, but your production server is using Ruby 1.9.1. CSV::Writer was deprecated with Ruby 1.9.
From the the docs:
# * The old CSV's Reader and Writer classes have been dropped.
Step one is to upgrade your local Ruby to the same version as the server. This will give you the same error locally, which should go away once you find and remove that CSV::Writer.
The CSV docs give examples of how to use the current CSV class to accomplish what CSV::Writer used to do. Here's an example:
# == Writing
#
# === To a File
#
# CSV.open("path/to/file.csv", "wb") do |csv|
# csv << ["row", "of", "CSV", "data"]
# csv << ["another", "row"]
# # ...
# end
Upgrading Ruby will probably raise other errors. But Ruby 1.8.7 was retired in 2013 so these are problems you're going to want to fix now rather than later.
Good luck!

How to resolve JSON syntax errors in rails?

I started learning rails using 'Agile Web Development with Rails, 4th Edition'
with
rails 3.2.7 and ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux].
When i tried to
edit an html form with
<%= f.text_area :description :rows=>6 %>
it returned an error
/media/ashku/New Volume/RoR/depot/app/views/products/_form.html.erb:19: syntax error, unexpected ':', expecting ')'
...= ( f.text_area :description :rows=>6 );#output_buffer.safe...
then i tried to change the :rows=>6 to rows: 6 but the results where the same
Discussion here suggests it as problem with JSON
controller code is given here
so how to resolve this problem ?
You have missed the comma(,) after tag name ie.(:description).
So replace your tag with following and try to run..
<%= f.text_area :description, :rows => 6 %>
You're missing a comma in between :description, and :rows.
You can use "Better Errors" gem for debugging in development env., this is a better tool to find errors in good way. read about them from http://railscasts.com/episodes/402-better-errors-railspanel?view=asciicast

Rails link_to syntax error: unexpected ',', expecting ')'

I recently attempted to add bootstrap-sass to my rails app, and it seemed to have broken all my links (the links were fully functional before installing the bootstrap-sass gem). I am using ruby 1.8.7.
A sample link I have is:
<%=link_to image_tag ("right_arrow.png", :size => '20x20'), project_step_path(#project, #step.number+1) %>
The error I am getting is:
syntax error, unexpected ',', expecting ')' ...o(image_tag ("right_arrow.png", :size => '20x20'), project_s...
Anyone know how to fix this?
There is an extra-space after image_tag.
image_tag ("right_arrow.png", :size => '20x20')
It should be
image_tag("right_arrow.png", :size => '20x20')

refinerycms engine i18n route error

need to have multiple language.
configured i18n.rb:
Refinery::I18n.configure do |config|
config.enabled = true
config.default_locale = :en
config.current_locale = :en
config.default_frontend_locale = :en
config.frontend_locales = [:en, :ru]
config.locales = {:en=>"English", :ru=>"Russian"}
end
generated engine in refinerycms:
rails generate refinery:engine product title:string description:text image:image --i18n title description
rails generate refinery:products
I'm getting the following error: No route matches {:locale=>:en, :controller=>"refinery/products/products", :action=>"show", :id=>"1"} when I try to open any page of engine
Please help!
After I added a custom engine to my CMS, I was having the same issue; my 'locale selector' in my application layout file caused the error you described:
-# Haml:
%ul.locales
- locales.each do |locale|
%li= link_to Refinery::I18n.locales[locale], url_for(:locale => locale), :title => Refinery::I18n.locales[locale], :class => "flags-#{locale}"
By changing url_for into refinery.url_for this solved the problem:
-# Haml:
%ul.locales
- locales.each do |locale|
%li= link_to Refinery::I18n.locales[locale], refinery.url_for(:locale => locale), :title => Refinery::I18n.locales[locale], :class => "flags-#{locale}"
Can't explain what happened yet, but maybe this will solve your problem.
To be honest, all credits should go to this answer :)
Did you run:
rake db:migrate
rake db:seed
after you did rails generate refinery:products?

Why is Paperclip failing silently in production + development?

I'm clueless as to what's going on with this because I have another app on the same server that receives and saves uploads just fine.
No error messages, Paperclip even say's in the log it's saving the attachments.
But the attachments don't get saved.
Thoughts anyone?
Also how would I test for this using RSpec/Capybara, because apparently my tests don't cover this.
Running Paperclip 2.3.12, Rails 3.0.9, REE1.8.7
Production on RHEL5 / Apache , but runs on a different user than my other app's user.
Update I get the same silent fail on development too!
But my test's pass and I can see the image being uploaded with the tests.
I believe you forget to add multipart option to your form
:html => {:multipart => true}
so
<%= form_for #my_object, :html => {:multipart => true} do |f| -%>
...
<% end %>

Resources