Rails doesn't expand the variable "count" when displays - ruby-on-rails

I am developing a Rails 2.3.8 app and I stumbled upon a strange form error:
in all errors messages in any input forms, the variable count is not expanded.
As instance if I fill in the following form with a too long string (> 300 chars, I've set max=300), the form will display the message:
"is too long (maximum is {{count}} characters)" instead of:
"is too long (maximum is 300 characters)"
- form_for(#event) do |f|
= f.label :description
%br
= f.text_area :description
= f.error_message_on :description
Do you have any ideas why this happens ?
many thanks

Redmine had this issue and they fixed it in 1.0.5.
See here for the changes:
http://www.redmine.org/news/49
in the message they say something along these lines:
Among 11 bug fixes, Redmine 1.0.5
solves the incompatibility with the
i18n 0.5.0 gem. The appropriate i18n
gem version (0.4.2) is now required
so i assume you need to install the 0.4.2 i18n gem :)

I was having the same issue, and installing i18n 0.4.2 solved it for me.

Related

Spree deface override tutorial

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.

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

Extra whitespace when rendering a text_area in Rails 3.2.3

I'm getting an extra white space inside the text area when rendering this HAML code.
= f.text_area :message, placeholder: "Reply"
I'm running Rails 3.2.3 and haml-rails 0.3.4 and haml 3.1.4
I have no idea why this is happening.
This is the code rendered with the extra whitespace
<textarea class="textarea" cols="50" id="idea_idea" name="idea[idea]" rows="2">
</textarea>
Just found a solution to this problem.
I upgraded to the "3.1.5" beta version of HAML and works fine now.
gem 'haml', :git => "git://github.com/haml/haml.git", :branch => "315"
The version you are running should have similar issues fixed, see the ActionPack Changelog linked below, it appears to contain multiple entries related to the issue.
https://github.com/rails/rails/blob/3-2-stable/actionpack/CHANGELOG.md

Having problems while generating barcode in rails using BARBY gem

I am using:
ruby 1.8.7, rails 2.3.5
ruby gems 1.3.6
Windows 7 Home Basic 64-bit
barby 0.5.0
I'm having problems to generate barcodes for my app. I installed barby 0.5.0 and I was hoping that it would solve my problems. But everytime it generates a file, it seems that it's broken or damaged. It can't be opened. I wonder what I'm doing wrong here.
As for the stack trace, there's really no error.
Here's my code:
barcodevalue = "00000000000"
full_path = "barcode#{barcode_value}.png"
barcode = Barby::Code39.new(barcode_value)
File.open(full_path, 'w') { |f| f.write barcode.to_png(:margin => 3, :xdim => 2, :height => 55) }
render :text => "#{barcode_value}.png has been generated."
Please see this link for answer.
https://groups.google.com/forum/#!topic/ruby-barby/8Vgh-CLNfuI

Validates_format_of?

1 error prohibited this {{model}} from being saved
There were problems with the following fields:
* {{attribute}} {{message}}
I am getting this error and code I am using is:
validates_format_of :user_id , :with => /\A(([0-9]{4})-[A-Z]{2}$)\Z/ , :message => "should be in the format 1111-TT", :allow_nil => true, :allow_blank => true
Any idea what's causing this?
I had this same problem using Rails 2 and i18n 0.5.0. Uninstall i18n 0.5.0 or specify the older version (I'm using 0.4.1) in your environment.

Resources