JRuby unexpected : - ruby-on-rails-3

I am running JRuby version 1.6.7 with Rails 3.2.3 and when I launch my rails server rails s I get the following error:
/config/routes.rb:8: syntax error, unexpected ':'
match '/about', to: 'pages#about'
However, if I change to match '/about' :to => 'pages#about' I don't get the error. Since this shorthand format is supported in the version of Rails in use, what is the problem and how do I resolve it?

The hash syntax comes from Ruby implementations, not Rails. JRuby can run in either 1.9 or 1.8 mode. It runs in 1.8 mode by default. You can read about configuring JRuby to run in 1.9 mode on the wiki.

The key: value syntax was introduced by Ruby 1.9 to supersede 1.8's :key => value syntax. The version of Rails is irrelevant; unless your version of Ruby is at least 1.9, you cannot use the new key: value syntax for hashes.

Related

unable to get the locale from client after Rails & Ruby update

formerly, I used Rails 3.2.13 with Ruby 2.0.0 and this worked fine :
In my application.rb, I had:
def set_locale
I18n.locale = http_accept_language.compatible_language_from([:en, :de])
end
I use 2 locales, de.yml and en.yml
Now that I upgraded to Rails 3.2.22 and Ruby 2.2.4, I was forced to also upgrade gem i18n to version 0.7.0, and I get the error message "I18n::InvalidLocale (:en is not a valid locale)" if I choose a client in 'en' or another language. 'de' works.
I tried various combinations of parameters in application.rb
config.i18n.enforce_available_locales = true
config.i18n.available_locales = ["en", "de"]
config.i18n.default_locale = :'de'
but to no avail...
If I use a client in 'de', it works, but if I use a client in 'en' or another language, I get the above error message. Formerly, if I chose another client language, it would default to 'de'
Downgrading i18n version to 0.6.4 and upgrading it again to 0.7.0 did the trick. I have no idea why.
I'm still not entirely satisfied with the result, though, since I cannot currently predict what happens if a client uses a language for which there is no locale in my app. Sometimes it picks :en, sometimes :de. I would prefer to be able to control the default language.

Session creation causes error with Rails engine generated under Rails 4.1

There are Rails 4.1 and 3.2.12 installed on our system (Windows). When generating Rails engine with:
rails plugin new engine --T --mountable --dummy-path=spec/dummy
The engine is generated with Rails 4 by default. Under spec/dummy/config, we notice that it is:
Rails.application.configure do
Instead of in Rails 3.2.12 engine:
Dummy::Application.configure do
It seems that the Dummy is replaced with Rails in Rails 4 engine. Then we changed the gemspec to rails, '~> 3.2.11' and bundle install and replaced Rails.application with Dummy::Application in dummy/config (now it is rails 3.2.12 in gemfile.lock). However there is error when creating sessions under spec/dummy:
rake db:sessions:create
The error is undefined 'configure' or undefined 'migration_error=' even after replacing Rails.application with Dummy::Application. There is not much info about what's new in Rails 4 engine. How to fix this problem?

undefined method `acts_as_mappable' trying to use geokit

I am trying to use geokit but I get the following message:
undefined method `acts_as_mappable'
I have tried the following solutions but nothing has worked so far:
Rails 3.1.0, geokit, with error acts_as_mappable
I am using rails 3.0.1 and ruby 1.9.2
I have followed the instructions here https://github.com/jlecour/geokit-rails3 but its not working
This is my model:
class Event < ActiveRecord::Base
acts_as_mappable :default_units => :kms,
:default_formula => :flat
end
and I have this in my gemfile
gem 'geokit-rails3'
I also have the folder vendor, inside I have a geokit-rails3 folder with the files, one of them named acts_as_mappable. I have tried adding require 'geokit-rails3' in the top of my model but it says no file to load.
I tried both, installing it as a plugin:
rails plugin install git://github.com/jlecour/geokit-rails3.git
and also by doing gem install (and it is shown when I list all the gems installed)
Any help is greatly appreciated.
The problem was solved by reinstalling rails with:
sudo apt-get install rails rails-doc rails-ruby1.8

RJS Handler missing

I got a missing template error when I tried to achieve a task using RJS.
All I want is to execute an RJS file on ajax call. But I am getting the
following error.
ActionView::MissingTemplate (Missing template line_items/create,
application/create with {:handlers=>[:erb, :builder, :coffee],
:formats=>[:js, :html], :locale=>[:en, :en]}. Searched in:
* "<MY APP PATH>/app/views"
):
app/controllers/line_items_controller.rb:46:in `create'
But the create.js.rjs is present in the folder /views/line_items. You
can see the handlers miss .rjs extension. I think thats causing the
error.
If I change .rjs to .erb, it works and the content is executed as
javascript and thus I need to modify the RJS functions to Javascript to
return the contents of AJAX call.
Could you please explain how I can attain this using RJS? Please help.
Following is the versions of tools I use.
Ruby version 1.9.2 (i686-linux)
RubyGems version 1.8.10
Rack version 1.3
Rails version 3.1.0
JavaScript Runtime Node.js (V8)
Active Record version 3.1.0
Action Pack version 3.1.0
Active Resource version 3.1.0
Action Mailer version 3.1.0
Active Support version 3.1.0
Thanks in advance.
in order to use RJS with Rails 3.1 you have to use the prototype-rails gem
Make sure prototype-rails gem is in bundler's production group. If you put it in the assets group it will not register the RJS template handler.

How to solve the following rails 3 error: ArgumentError (Syck is not missing constant BadAlias!)?

I've got a strange error with a rails 3.0.3 application running on ruby 1.9.2, as a matter a fact it doesn't run yet, beacause I get the following error:
ArgumentError (Syck is not missing constant BadAlias!):
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (14.4ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.4ms)
Is because of the ruby version? Or how can I solve this?
-- later edit:
On ruby 1.8.7 EE, I have no such error.
After searching and searching the internet, I started to look at all my YAML in my app, and I validate each file using: http://yaml-online-parser.appspot.com/, and I've got errors like:
while parsing a flow node
expected the node content, but found ':'
in "<unicode string>", line 147, column 13:
order: [:day, :month, :year]
Therefore everything was because the yaml errors. The problem is with unicode, in seems that its different on ruby 1.9.2 than in 1.8.7.