ruby-on-rails

Parse string as if it were a querystring in Ruby on Rails

I have a string like this: "foo=bar&bar=foo&hello=hi" Does Ruby on Rails provide methods to parse this as if it is a querystring, so I get a hash like this: { :foo => "bar", :bar => "foo", :hello => "hi" } Or must I write it myself? EDIT Please note that the string above is not a real querystring from a URL, but rathe...

Seeding a Rails Database with Pre-set IDs

I have an XML file containing seed data that I'm trying to load into my production database. The problem being that I have associations between different data types / nodes in the XML file, and so I need the specified IDs to be the same when loaded into MySQL from Rails. This works fine with SQLite during development, I just use a line...

Rails find :conditions

I have a Reservation model that I'm searching for with three fields. The container_id must always be self.id but as confirmed and auto_confirmed only one needs to be true. I have the following but it doesn't perform what I need: Reservation.find(:all, :conditions => ['container_id = ? AND confirmed = ? OR auto_confirm = ?', self.id, ...

Factoring out conditional from Rails view

I have a line of code in a basic Rails blog application I did that determines whether the suffix to the number of comments should be "comment" (if 1) or "comments" (0 or 2+) Currently, it is a line in the view looking like this: <%= post.comments.count() %> <%= post.comments.count() == 1 ? "comment" : "comments" -%> However, sinc...

Rails: updating an item along with associated items

Suppose I have a simple to-do list application. The application contains two models: lists (have an owner and description) items (have name and due-date) that belong to a specific list I would like to have a single edit screen for a list in which I update the list attributes (such as description) and also create/delete/modify associa...

HABTM checking for match of latest 3

Here's an interesting one for you folks... I have a HABTM (has_and_belongs_to_many) relationship between "Dogs" and "Trips". My goal is to find two result sets: 1) Dogs that have been on at least 1 of the last 3 trips and call that @dogs_current 2) Dogs that have NOT been on any of the last 3 trips and call that @dogs_old I found that...

Escape doube and single backslashes in a string in Ruby

Hello. I'm trying to access a network path in my ruby script on a windows platform in a format like this. \\servername\some windows share\folder 1\folder2\ Now If I try to use this as a path, it won't work. Single backslashes are not properly escaped for this script. path = "\\servername\some windows share\folder 1\folder2\" d = Dir...

Best way to add comments in erb

What is the best way to add comments in erb files, if we do not want them to be generated into the html content? ...

Drop mysql tables in Rails

How do I drop selected tables in Rails? I want to drop all tables from a database with a given prefix. PHPMyAdmin would be very useful at this point. Thanks ...

Aliasing a namespaced route in Rails

Hi all, Given the following routes.rb file: # Add Admin section routes map.namespace :admin do |admin| admin.resources :admin_users admin.resources :admin_user_sessions, :as => :sessions admin.resources :dashboard # Authentication Elements admin.login '/login', :controller => 'admin_user_sessions', :action => 'new' ...

Rails two-legged OAuth provider?

I have a rails 2.3.5 application with an API I wish to protect. There is no user - it is an app to app style webservice (more like an Amazon service than facebook), and so I would like to implement it using a two-legged OAuth approach. I have been trying to use the oauth-plugin server implementation as a start: http://github.com/pelle...

Nokogiri pull parser (Nokogiri::XML::Reader) issue with self closing tag

I have a huge XML(>400MB) containing products. Using a DOM parser is therefore excluded, so i tried to parse and process it using a pull parser. Below is a snippet from the each_product(&block) method where i iterate over the product list. Basically, using a stack, i transform each <product> ... </product> node into a hash and process ...

Facebooker and graph API, get news feed

Hi, How to get the news feed for a user with facebooker? If it is not possible, how can I use the graph api to take advantage of the fact that the user is already logged in with facebooker, and has a facebook_session active. Thanks ...

CPanel and Ruby on Rails issue

I am running CPanel and recently discovered that I can install RubyonRails there too (http://docs.cpanel.net/twiki/bin/view/AllDocumentation/RubyonRails/WebHome) I have the new icon RUBY ON RAILS in my CPanel (after installation following the instruction from the link above). Now when I create a test application, it runs OK but when I c...

Rendering HTML in rails without actually displaying it

Hello all, My current project requires me to assemble a .zip file containing HTML and text-only templates for a user to download, for importing into an email marketing program. I've inherited this project, and currently the code uses a "fake" model (that is a model that does not directly correlate to a database table), in which it stor...

Rails - dynamically adding to sortable_element

Am adding to a sortable list using Ajax, and to get the Scriptaculous effects to kick in after the add, the only way I have found is by re-executing sortable_element. Can anyone suggest a better way of doing this, at the complete code is a hack: <%= link_to_remote "Add", :url => { :controller => "pages", :action => "add_fragme...

Is devise compatible with declarative_authorization?

Just asking whenever devise authentication mechanism for Rails does not conflict with declarative_authorization. Maybe someone tried this combo and can share their knowledge, so I and other coders do not waste time trying to tie these ones up. ...

like-vim emacs ruby indentation

ruby-mode from svn, looks equal to 1.1 version here is emacs indentation of hash User.all({ :joins => :account, :conditions => {:delete_at => nil} }) here is the same in vim User.all({ :joins => :account, :conditions => {:delete_at => nil} }) How to make emacs indent like vim in ruby-mode? ...

Limesurvey alternative for Ruby on Rails?

Does anyone know of a full featured survey tool for rails? Like Limesurvey (PHP -unfortunately for my purposes.)? Tried to look on Ruby-toolbox, but it seems to be down. ...

Named Blueprints with factory_girl

I am using Factory Girl but like the machinist syntax. So I wonder, if there is any way creating a named blueprint for class, so that I can have something like that: User.blueprint(:no_discount_user) do admin false hashed_password "226bc1eca359a09f5f1b96e26efeb4bb1aeae383" is_trader false name "foolish...