rails 3.1 key value problem - ruby-on-rails

rails 3.1 with ruby 1.9.2p290 on windows generates
initialers/config/session_store.rb
Hello::Application.config.session_store :cookie_store, key: '_hello_session'
key: 'hello_session' is :key => 'hello_session' in some of my old apps. What makes rails to generate different codes? Ruby version or rails version ?

There's a new hash syntax in ruby 1.9, you can write:
{key: "hello_session"}
instead of:
{:key => "hello_session"}
The 1.8 syntax is still supported, use it if you want your app to be compatible with both 1.8 and 1.9.

I resolved this by removing my ~/.rvm directory and reinstalling RVM.

Related

How do I specify to rails which version of ruby I would like to use?

Before judging this question please listen to these details:
I have tried twenty million things to "update" ruby so that it is compatible with ruby on rails. The problem is that I cannot make changes to anything in the bin of my macbook. The terminal simply does not allow it. So, I installed a new version of ruby via the command line that is 2.5.1. How do I direct rails via the terminal to use this version instead of the version in my bin?
From the official Rails Guides website.
Rails 6 requires Ruby 2.4.1 or newer.
Rails 5 requires Ruby 2.2.2 or
newer.
Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer.
Rails 3.2.x is the last branch to support Ruby 1.8.7.
Rails 3 and above require Ruby 1.8.7 or higher.
While Rails 6 is still unreleased, this is a preliminary guess, given from the current master-branch of the official repository, at https://github.com/rails/rails/blob/master/guides/source/upgrading_ruby_on_rails.md
From edge-guides:
http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#ruby-versions

Ruby 2 Upgrade Breaks Nokogiri and/or open-uri Encoding?

I have a mystery to solve when upgrading our Rails3.2 Ruby 1.9 app to a Rails3.2 Ruby 2.1.2 one. Nokogiri seems to break, in that it changes its behavior using open-uri. No gem versions are changed, just the ruby version (this is all on OSX Mavericks, using brew, gcc4 etc).
Steps to reproduce:
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin13.1.0]
$ rails console
Connecting to database specified by database.yml
Loading development environment (Rails 3.2.18)
> feed = Nokogiri::XML(open(URI.encode("http://anyblog.wordpress.org/feed/")))
=> #(Document:0x3fcb82f08448 {
name = "document",
children = [
..
> feed.xpath("//item").count
=> 10
So all good! Next, after a rvm change to Ruby 2.1.2 and a bundle install..
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
$ rails console
Connecting to database specified by database.yml
Loading development environment (Rails 3.2.18)
> feed = Nokogiri::XML(open(URI.encode("http://anyblog.wordpress.org/feed/")))
=>
> feed.inspect
=> "#<Nokogiri::XML::Document:0x86a1f21c name=\"document\">"
> feed.xpath("//item").count
=> 0
So it looks like the 'open' encoding has changed, in that a gzip http stream isn't being fed correctly to nokogiri? I checked with a nokogiri -v and it is using the packaged xml libs rather than system ones. Is this a open-uri Ruby 2.1.2 issue?
Another theory is that one of the gems has monkey patched open-uri to fix something in 1.9 and that is breaking 2.1? Help or ideas please!
EDIT: Here's more info not using Nokogiri, i.e. thinking this is more a open-uri issue on Ruby 2.1.2:
> open(url) {|f|
* f.each_line {|line| p line}
* p f.content_type
* p f.charset
* p f.content_encoding
* }
"\u001F\x8B\b\u0000\u0000\u0000\u0000\u0000\u0000\u0003\xED\x9D\xDBr\eW\xB2\xA6\xAF\xED\xA7\xA8\xCD\u001E\xB7/$\u0010..
(snip)
3\xF3\xA79\xA7\xFAɗ\xFF\u000F\xEAo\x9C\u0014k\xE8\u0000\u0000"
"text/xml"
"utf-8"
["gzip"]
=> ["gzip"]
..the 1.9 version was readable, i.e. gzip was applied already.
If I go into a clean ruby irb it works ok, so it must be something in my rails gems that is changing the behavior of open-uri open to not deflate/gzip. I have a lot of gems referenced.. :(
Ok, here's an answer, and maybe the answer. Ruby 2 changed how it uses headers in HTTP requests and zipping/deflating, but at some point they changed their minds back and put it to be how 1.9 worked. In the interim some Rails gem maintainers monkey patched HTTP:Net to make their gems work on both 1.9 and 2.0. Those monkey patches still linger in older versions of gems and cause issues like I saw upgrading from 1.9 to 2.1
A summary of the issue and solution here:
http://avi.io/blog/2013/12/17/do-not-upgrade-your-rails-project-to-ruby-2-before-you-read-this/
We use the gem right_aws, and the details of that issue with ruby versions is here:
https://github.com/sferik/twitter/issues/473
The solution was to undo the monkey patch using this as a gem reference in our Gemfile:
gem 'right_http_connection', git: 'git://github.com/rightscale/right_http_connection.git', ref: '3359524d81'
Background reading and more info:
https://github.com/rightscale/right_aws/issues/167

getting error in generator active_admin:resource -> key: '_manager_session'

i want to resolve this error, anyone please, this error is about syntax error in session_store.rb file, at attachment in pastie:
http://pastie.org/2681282
It looks like you're trying to use Ruby 1.9-style Hash syntax (key: value) in Ruby 1.8. Either upgrade to Ruby 1.9 or change your code to use the Hash syntax supported in Ruby 1.8, i.e. :key => '_manager_session'.
Checkout my answer here:
Mac OSX Snow Leopard - Rails error: Session_store.rb

SyntaxError on the welcome to rails screen using Pow

I have just set up a new project which displays all the correct info in the about your applications environment window when on http://localhost:3000/ but when I run it at http://egg.dev/ I get:
SyntaxError: /users/davidhall/work/egg/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
...sion_store :cookie_store, key: '_egg_session'
^
I'm sure I had this problem earlier, which was due to me using rails 3.1 with ruby 1.8.7, the problem resolved when I used ruby 1.9.2. Now I'm getting when using 1.9.2 too.
Thanks for any help its much appreciated!
The Problem is that, there is a new-style hash argument available in Ruby1.9.2 but unavailable in Ruby1.8.7 which is
key: value # only available in 1.9.2
||
:key => value # available in 1.8.7 and 1.9.2
so, with a less effort, you can just modify the syntax to the one that 1.8.7 recognized.
As you can read in the Pow User's Manual under point 2.3 you have to add a .rvmrc into the root directory of your project with the content rvm 1.9.2.
Then it should work!
I resolved this by deleting the ~/.rvm directory and reinstalling RVM.

Rails + rubygems + rvm disaster/confusion

I'm not sure exactly what I did but I messed up the Ruby/gem harmony trying to get an older 2.3.5 Rails app working on my system.
I'm currently using Ruby 1.9.2-p0 and rubygems 1.5.7. I've tried the newest one 1.8.2 but it just generates more warnings. I use these alongside of RVM.
I get "can't convert Symbol into Integer" when trying to boot a 2.3.x Rails app no matter what version of rubygems I run. I tried 1.5.7, 1.7.2, and 1.8.2.
$ script/server
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
path/.rvm/gems/ruby-1.9.2-p0/gems/rails-2.3.5/lib/rails/gem_dependency.rb:51:in `[]': can't convert Symbol into Integer (TypeError)
Any idea how I can get my system back in harmony?
As Dex and The Tin Man suggested in the comments, the solution was to run rails 2 on ruby 1.8.7 and rails 3 on ruby 1.9.2 using vrm. The warnings generated by rubygems 1.8.2 (now 1.8.3) are solved by running his suggest commands.

Resources