ruby

How to match string with complex delimiters (regex in ruby)

Hello I would like to match attribute pairs from string similiar to the one below <tag_name attra="#{t("a.b.c")}" attrb="aa a"> ... sould match on attra="#{t("a.b.c")}" and attrb="aa a" thanks in advance Marius ...

Canonical File Path in Ruby

Is there an easy way in Ruby to find a canonical file path out of a messy file path? For example: a/b/../c/x is the same as a/c/x a/./b/c/x is the same as a/b/c/x a/./b/../../c/x is the same as c/x Any simple way to do this? ...

How to load my rails console with spanish

I have set up a my application with spanish and english. On my console i am getting error messages in english if object is returning validation error. I want to set my rails console so i will get validation error message in spanish. ...

Higher order iterators in Ruby?

I was reading a Ruby question about the .each iterator, and someone stated that using .each can be a code smell if higher order iterators are better suited for the task. What are higher order iterators in Ruby? edit: Jörg W Mittag, the author of the StackOverflow answer that I was referring to mentioned that he meant to write higher lev...

Post nested params (hash) using HTTPClient

I needed a to have a multipart http post from one app to another that included a file attachment and a nested params hash. I tried using HTTPClient which worked for the file attachment, however I could not get params to send in a nested format. data_params = Hash.new data_params[:params] = Hash.new data_params[:params][:f] = Hash.new...

Generate ruby classes from json document

Consuming a ruby json API, I want to save me some work and generate ruby objects off the bat. Any way to do this? so you could transform this: {"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": "CreateNewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value...

Anyone know about Rhomobile?

I read about http://rhomobile.com/ and I found this is great but I want to ask whether the application built with that would run in Browser or Natively on the device as this requires HTML and Ruby? ...

How come this works and doesn't work in IRB?

I have Users . Users have_many :organizations If I do: User.find(:all).select {|u| u.organizations.first.name } it returns with: NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.name from (irb):33 from (irb):33:in `select' from (irb):33 Long story short: I am trying to find t...

Using SQL function as a group by field in datamapper (ruby)

I'm trying to use a slightly more interesting GROUP BY cause than what seems to be supported out of the box by DataMapper. The query I want to generate looks something like this: SELECT SUM(downloads), SUM(uploads) FROM daily_stats GROUP BY YEARWEEK(date) I'd like to be able to just tell DataMapper something along these lines: DailyS...

ruby, check if integer is within a range

I don't know if I'm just searching for the wrong things or what, but is there a simple way to evaluate a range and check if an integer is within that range using the (2..100) syntax. Like just say I wanted to evaluate as true if my integer x = 100, and my range is (2..0), I'm just looking for the simple, concise ruby-way of doing this. ...

Rpam ruby module and PAM service name

It appears that the best PAM module for ruby is "rpam". However this module hard codes the service name "rpam" when calling pam_start which seems to be denied by default on at least RHEL. I can get rpam to work by hacking the source to change the hardcoded service name to something present in /etc/pam.d. Do people normally reconfigure P...

In Ruby, what is the equivalent to an interface in C#?

Hi, I'm currently trying to learn Ruby and I'm trying to understand more about what it offers in terms of encapsulation and contracts. In C# a contract can be defined using an interface. A class which implements the interface must fulfil the terms within the contract by providing an implementation for each method and property (and mayb...

How to create a regexp that matches a pattern except for some strings in Ruby?

I work in Ruby, and have to create a single regexp for the following task, as I'm working with someone else's gem that uses this regexp to match fields to be worked on in a text file. I need to match beginning of string, any set of characters, and underscore, then any multi-digit integer that is not 1,2, 9, or 10, and end of string. I.e....

warning: getc is obsolete; use STDIN.getc instead

Hello, I'm having a problem with my rails application. When I type script/server I get the following error: /Users/admin/.gem/ruby/1.8/gems/activesupport-2.3.5/ lib/active_support/multibyte/unicode_database.rb:37: warning: getc is obsolete; use STDIN.getc instead This causes the application to hang and not respond. How can I...

SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A

Hi, I have a ruby client that connects to an exchange server using IMAP & SSL. I use the Ruby Net::IMAP library (which uses openssl under the covers) to connect. Its been working fine for months. The exchange server admin installed new cert from godaddy and now I get this error: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 rea...

remote form_tag in rails3 without a named route

what is the proper incantation to make this actually post asynchronously? form_tag :controller => :magic, :action => :search, :method => post, :remote => true do method=post and remote=true just get squashed on the end of the url instead of actually making it an ajax post. ...

Append row to csv file Ruby 1.9 CSV lib

Using Ruby 1.9 and CSV lib, I can't seem to append a row. The example in the documentation opens the file, and overwrites the row. What is the correct way to append rows to the document? Example from documentation: require 'csv' CSV.open("path/to/file.csv", "wb") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row...

Why is ruby on rails returning null instead of json object

I'm new to Rails so this is really basic and I'm sure I'm missing something simple. I'm trying to send some JSON to an action and get it to return a response in JSON. A simplified version of what I'm trying is below. The jQuery I'm using: var request = { 'voter': { 'voter_name': 'John', 'voter_email': '[email protected]'} }; var url = '...

Can I point a Heroku project to a Path in my Domain?

If I have a project on heroku: http://martini.heroku.com Can/how-do I point that to a path on my domain: http://viatropos.com/martini Is that possible? ...

problem with project MVC structure

in my project i have about 20 html forms with many different <input>'s. This <input>'s are unique in every form and they don't repeated between them. For each form there is a script which get data from form, generate specific file, and push it to the browser. and that's it. no databases, admin, logins/passwords and other usual web-app st...