ruby

Problem with post in Sinatra

I'm using JQuery to post in a Sinatra application. $.post("/addnewlistitem", $('#inputrow1').val(), function(data){alert(data);}); Haml looks like this: %input{:type => "text", :id => "inputrow1", :name => "item", :class => "txt"} And the ruby code, like this: post '/addnewlistitem' do @v = params[:item] end The problem is ...

How to fix difference in behavior of activesupport 3.0.0 compare to 2.x?

I am using Hash#to_xml in my Sinatra application. It did work till I moved to actviesupport 3.0.0 Is there a difference in usage of activesupport in 3.0.0? For example this works fine gem 'activesupport', '2.3.5' require 'active_support' {}.to_xml and gem 'activesupport', '3.0.0' require 'active_support' {}.to_xml generates: N...

How to properly pass collection for input in Formtastic

I need to pass a collection to the standard select input in Formtastic: f.input :apple, :as => :select, :collection => Apple.all The problem is, though that I need Formtastic to access a different method than name. Now this is really a problem. I can always pass the Array f.input :apple, :as => :select, :collection => Apple.map { |a|...

Failed WATIR installation Server 2003

Hi all, I had to rebuild my box and I currently am unable to install Watir. gem install watir ERROR: Error installing watir: activesupport requires Ruby version >= 1.8.7. Which would be fine if Watir was able to use Ruby 1.8.7 . I am using ruby -v ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] ge...

What is the difference between where 'require' looks and where 'Gem.available?' looks for gems?

I'm a bit confused about how paths work with gems. Here's the core of my confusion: >> require 'rubygems' => false >> Gem.available?('money') => true >> require 'money' LoadError: no such file to load -- money from (irb):3:in `require' from (irb):3 from /usr/bin/irb:12:in `<main>' >> Gem.available?('pony') => fa...

Returning a variable value to a rake script

I'm executing a rake script that calls a powershell function. The function returns a value, how can i get this value and provide it to my rake template file? Thanks for any suggestions ...

"gem update --system is disabled on Debian" error

When I try to update rubygems (by running 'gem update --system') I get this error: ERROR: While executing gem ... (RuntimeError) gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get. Any idea what might be wrong and how I can fix it? ...

What is the difference between ri and rdoc

Whenever I install gems I see ri and rdoc follow. I know this is documentation but what is the difference between the two and how to use them? ...

Python or Ruby Which one should I learn?

I am new to programming.. I was thinking to start learning with Ruby or Python. y main task would be web development. But I cannot choose between them. Which language do you think I should learn? ...

RVM cannot use ruby with sudo

Hi guys, I've just started playing with Ruby Version Manager (http://rvm.beginrescueend.com/rvm/cli/). I have succefully configured rvm to use ruby 1.9.2 and everythin is fine. However when I'm trying to do something using sudo no rvm or installed ruby is detected administrator@hosting-live-2:~$ ruby -v ruby 1.9.2p0 (2010-08-18 revis...

How can I avoid truthiness in Ruby?

Is there any standard way to avoid truthiness in Ruby, or would I need to roll my own solution, such as class FalseClass def to_bool self end end class TrueClass def to_bool self end end true.to_bool # => true false.to_bool # => false nil.to_bool # => NoMethodError 42.to_bool # => NoMethodError Background: I know tha...

How do I avoid the "Useless use of == in void context" in RSpec?

In RSpec, if I have warnings on and have x.should == 42 another_line_of_code then I get a warning about warning: useless use of == in void context Is there anything I can do other than Turn warnings off Change it to bitbucket = (x.should == 42) ...

Rails if statement results in illegal octal digit error?

Hi Everyone, I have the following if statement in my view: <% if @kase.jobno[1,2].to_i == 10 then %> <img src="../images/2010.jpg" alt="2010"> <% elsif @kase.jobno[1,2].to_i == 11 then %> <img src="../images/2011.jpg" alt="2011"> <% else %> <img src="../images/document.jpg" alt="Document" /> <% end %> It works absolutely perfe...

HBase ORM for Ruby

What HBase ORM/adapters for Ruby exists? Which are the best? WHY? ...

Where is the application.rb file located ?

Hello, Im new to Ruby On Rails.Im using Ruby version 1.8.7 and Rails version 2.3.8.I created a controller SayHello using ruby script/generate controller SayHello The application works as expected, but i cant find the application.rb file. Where is the application.rb file located ? Please Help Thank You ...

Groups in a Gemfile in Rails 3?

In my Gemfile in Rails I have these groups: group :development, :test do gem "capybara" gem "database_cleaner" gem "spork" gem "launchy" end group :bdd do gem "cucumber-rails" gem "rspec-rails" end What does this mean? ...

In ruby-on-rails, how to convert the '\X93' like string format to its original look?

s = "你好" s.encoding # => #<Encoding:UTF-8> yaml = s.to_yaml # => "--- \"\\xE4\\xBD\\xA0\\xE5\\xA5\\xBD\"\n" yaml.encoding # => #<Encoding:ASCII-8BIT> yaml.force_encoding 'utf-8' # => "--- \"\\xE4\\xBD\\xA0\\xE5\\xA5\\xBD\"\n" Then, how to make the 'to_yaml' generate original looking: "你好", I mean not something ...

Using cloned git repo instead of gem?

I'm using the Thor gem, but I have cloned the git repo to a folder and I want the system to use that one instead and not the gem, because I have added a feature in the cloned repo and want to test it. How do I tell the system (Ubuntu 10.4) to use the cloned repo and not the installed gem. ...

Accessing child attributes from parent Factory Girl factories

I'm implementing Factory Girl as a replacement for fixtures in my Rails app. I have several tables that I'm trying to represent using associations. However, to throw a kink into the loop, beyond just defining the associations, I also need to access attributes of the child factories from the parent. Below is an example of what I'm tryi...

Real Life (yet simple enough for a beginer) Example of TCP and/or UDP Sockets

I have been attempting to learn tcp/udp for so long now, I am on the brink of giving up completely and never attempting it again, I have read every tutorial there is but can never get anything to work. Tutorials either stop once they tell me how to connect and dont explain how it can be used or do not provide enough source code. Is there...