ruby

Upgrade to Rails3 from Rails3.rc2, and forms are blank...

Using ruby 1.9.2 if I change gem 'rails', '3.0.0.rc2' to gem 'rails', '3.0.0' None of my forms render. My forms all use <%= %> and everything works great in rc2. I don't even get any errors. <%= form_for(@user) do |f| %> Not even this text would render.... Its not even hidden on the page. <% end %> This is my GEMFILE: ...

user.find(1) results in an exception, is my system ok or my setup is messed up?

My database is empty, and I understand that I should get an exception. Just want to make sure that my macbookpro is setup with rails properly. typing: user.find(1) in console I get: >> user.find(1) NoMethodError: undefined method `find' for #<User:0x1016403a0> from /Library/Ruby/Gems/1.8/gems/activemodel-3.0.0/lib/active_model/a...

How can I authenticate my POST request via OpenId on the commandline

I want to add entries to my RESTful Rails blog using HTTP POST requests. I have a script that does this easily enough, but it only works for my development app because I don't require it to authenticate. Now that I'm publishing my site, I obviously need to authenticate my uploads before posting them. The rest of the admin stuff is behin...

Traversing a Hash Recursively in Ruby

I'm having a problem with this function that traverses a Hash. The Hash may contain an Array of Hashes. I want the method to search for an id and then return just the nested hash it finds. It seems to work for the traversal, but it returns the original value passed in. require 'rubygems' require 'ruby-debug' def find_by_id(node, find...

Different tags in ERB

I'm just getting started with Ruby and Ruby on Rails, so excuse me if this is a simple question. I've noticed that in some ERB files, there is a difference to using <%= %> and <% %>, but what is the difference? Thanks! ...

How to prevent pipe character from causing a Bad URI Error in Rails 3/Ruby 1.9.2?

In implementing OAuth2 in my app, I need to handle URIs like: http://localhost:3000/sessions/create/?code=lorem|ipsum Not sure if it's a Rails 3 or Ruby 1.9.2 problem (maybe URI.parse), but in any event, WEBrick kicks Error bad URI. Anyone know of a workaround? Thanks. ...

how do I pattern match a string within a string and then extract it into a variable

I have come across a problem that I cannot see to solve. I have extracted a line from a web page into a variable. lets say for argument sake this is: rhyme = "three blind mice Version 6.0" and I want to be able to first of all locate the version number within this string (6.0) and secondly extract this number into another seperate vari...

How can I chomp an array in ruby?

Ok this is not a biggier but in the interest of writing cleaner code? IO.popen("Generate a list of files").readlines.each{|f_nl| f=f_nl.chomp # ... } Namely is there someway to chomp the whole array in one fell swoop? ...

Preferred Ruby-ist way of declaring access controls

This is a simple style question. What is the preferred means for declaring access controls in Ruby code? Example A: #!/usr/bin/env ruby class MyClass def method1 # this is public by default #... end protected # subsequent methods will be protected def method2 #... end privat...

Ruby on Rails: CSS and skins management

I have a skin support in my app. I'm looking for a tool, which will enable the customer (not the programmer, which is current) alter the skins. Is there an admin tool (gem, plugin) for Rails to manage (edit, create, view) these skins? I looking for some easy solution like /admin/skins page where I could do all the stuff, otherwise I'm g...

How to use objects with xsi:types in Savon

I'm trying to use Savon to make some SOAP requests, but I'm afraid I need to go beyond the basics somewhat. I need to send something along the lines of: <env:Body> <wsdl:methodName> <parameter xsi:type='ValueClass'>value</parameter> </wsdl:methodName> </env:Body> Now, if I didn't have to specify that xsi:type, it would be a s...

Get the evaluated HTML code from a template in Ruby on Rails

For some reason, I want to store the HTML code outputted from render into a database. For example, this is the content of a template (app/views/mailer/someview.html.erb): Hello <%= @foo %>. And I would like to store "Hello Jim." in my database by providing the template (mailer/someview) and the variables to replace (:foo => "bar"). ...

How do I avoid cross-thread violations in a Ruby extension?

I'm writing a C extension, providing an interface between Ruby and an asynchronous I/O library. When running the tests over my code, I frequently get errors including (but not limited to): [BUG] cross-thread violation in rb_thread_schedule() Asynchronous IO means my C extension will need to deliver messages to ruby from multiple threa...

ruby how to define writer method with "<<"

Hello, I have a skeleton class: class Foo def bar # returns some sort of array end end but how can one add the 'writer' method to 'bar' so to enable the Array#push behavior? Foo.new.bar<<['Smile'] _.bar #=> ['Smile'] EDITED: I should expand my question further. There are two classes. Foo, and Bar, much like the ActiveRec...

Ubuntu 10.04 - RVM won't set a default ruby.

Hello, I've managed to install RVM on a Linode VPS before, but after a rebuild I'm running in to all kind of problems and thought I'd see if anyone here could advise. I'm trying to install RVM (and Ruby 1.9.2) on a Linode Ubuntu 10.04 (32 Bit) VPS. I've tried following the instructions on many sites, such as http://web2linux.com/insta...

Is there a way to make changes to the titlebar with GTK2?

Hi there. I have a desktop application written in Ruby that is using GTK2. It's just a small test application to play with GTK2, but I'm having problems achieving what I want to do. Is there any way using GTK2 to get at the titlebar (apart from setting the title), specifically to either add a button to it (beside the min/max/etc, B in th...

Why can't I call `history` from within Ruby?

I can run Bash shell commands from with a Ruby program or irb using backticks (and %x(), system, etc). But that does not work with history for some reason. For example: jones$ irb --simple-prompt >> `whoami` => "jones\n" >> `history` (irb):2: command not found: history => "" From within a Ruby program it produces this error: /usr/lo...

Rails 3 ActionDispatch scope options

Do you know a resource which documents all the available options for the ActionDispatch scope method and their usage? I'm quite tired of digging into each merge_X_scope method trying to understand the X option implications. ...

How to empty a READ buffert.

I have a pipe opened. Eg. PTY.spawn('screen -x') do |read, write, pid| # code end After several writes I want to empty the read so when I use: read.each do |line| # code end it will start to read from that point I emptied it. How do you do this? ...

Parse, edit and output CSS in Ruby

Is there a gem to perform css editing and parsing in Ruby? What I need is to open css file, perform a find by a selector, alter it and save the output. The best way would look as following: draft = CSSParser.load('structure.css') draft.find('#header a').style('color', '#333') draft.render What's the most appropriate way to do that? ...