ruby

Getting Started with RSpec - Looking for tutorials

I'm looking to get started building a project and want to use RSpec from day one. My Ruby background is limited, however, I do have a good understanding of MVC and the structure within Ruby. In doing some research for books and tutorials, I've found no currently published books, and have found no tutorials that give a good "hello world"...

syslog output for log4r example

Hi, Can some one post an example of using syslog outputter for log4r, I am currently using stdout but want to log to syslog. mylog = Logger.new 'mylog' mylog.outputters = Outputter.stdout mylog.info "Starting up." raj ...

Is there a PHP or general programming book similar to why's (poignant) guide to ruby?

why's (poignant) guide showed me that programming could be a fun and creative act The things I particularly like about the book: Metaphors for concepts and syntax that really stick in your mind, and make reading code fun (hey, I recognise that guy!) Irreverent examples that are far removed from 'business logic' (text adventures, etc....

How do I solve "index unique_schema_migrations already exists" in Rails?

Running rake db:migrate followed by rake test:units yields the following: rake test:functionals (in /projects/my_project) rake aborted! SQLite3::SQLException: index unique_schema_migrations already exists: CREATE UNIQUE INDEX "unique_schema_migrations" ON "ts_schema_migrations" ("version") The relevant part of db/schema.rb is as follo...

What is your version control and deployment workflow with Rails?

Especially when considering a fresh Rails project, what does your version control and deployment workflow look like? What tools do you use? I'm interested in answers for Mac, *nix and Windows work machines. Assume a *nix server. I'll edit for clarity if need be. ...

How does ruby on rails work?

I'm a PHP developer who knows a little bit of Ruby. I want to learn Ruby on Rails, but most of the resources I've come across treat RoR functionality as "magic" -- i.e., it has a certain internal consistency, but don't bother asking how it works in terms of Ruby, MySQL, etc. Anyway, I want a deep understanding of how RoR works, the desi...

Find records with more than one ActiveRecord HABTM Association

I've got two models, joined by a Has and Belongs To Many join table. Lets call these models User and Event. The majority of Users have 0 events, while few have one or more. I want to do something like: User.find(:all, :joins => :events, :conditions => ["'Something that count the events' > ?"], 0) The problem is, I'm not sure how to s...

acts as taggable with merb?

Is there a acts as taggable solution out there for merb users already? ...

Using regex to replace all spaces NOT in quotes in Ruby

I'm trying to write a regex to replace all spaces that are not included in quotes so something like this: a = 4, b = 2, c = "space here" would return this: a=4,b=2,c="space here" I spent some time searching this site and I found a similar q/a ( http://stackoverflow.com/questions/79968/split-a-string-by-spaces-in-python#80449 ) that w...

Find out which keyboard layout is used, using ruby.

How can I find out, which keyboard layout the user of my ruby application is using? My aim is to have a game, where you can move the player on a map. To go one step down and one step left you press "Y" on a german keyboard. On an American keyboard, you would press "Z". We optimized the game for windows and mac, so I would like a solution...

Ruby to Python bridge

Hello I am interested in getting some Python code talking to some Ruby code on Windows, Linux and possibly other platforms. Specificlly I would like to access classes in Ruby from Python and call their methods, access their data, create new instances and so on. An obvious way to do this is via something like XML-RPC or maybe CORBA but ...

Does Ruby best practice shun statement modifiers after, for example, a long code block that is passed to an iterator?

something.each do |x| #lots of stuff end if some_condition ...

Could I improve this method with duck typing?

Hopefully I haven't misunderstood the meaning of "duck typing", but from what I've read, it means that I should write code based on how an object responds to methods rather than what type/class it is. Here's the code: def convert_hash(hash) if hash.keys.all? { |k| k.is_a?(Integer) } return hash elsif hash.keys.all? { |k| k.is_a...

Best ruby idiom for "nil or zero"

I am looking for a concise way to check a value to see if it is nil or zero. Currently I am doing something like: if (!val || val == 0) # Is nil or zero end But this seems very clumsy. ...

Column order of results from rails ActiveRecord find_by_sql call.

I'm attempting to put together some basic report screens. I've got some fairly complicated SQL queries that I'm feeding into ActiveRecord's find_by_sql method. The problem I am having here is that I am losing the order of the columns as given in the original query. I'm assuming that this is because the Hash class does not preserve ent...

How do I access "assigns" after "render :template => ..."?

I have an error handling method in my ApplicationController: rescue_from ActiveRecord::RecordNotFound, :with => :not_found def not_found(exception) @exception = exception render :template => '/errors/not_found', :status => 404 end In RAILS_ROOT/app/views/errors/not_found.html.erb, I have this: <h1>Error 404: Not Found</h1> <%= d...

POST request in namespaced resource controller going to index action instead of create

I have a namespaced controller for some admin functionality. My create form does not work -- it ends up routing the request to the index action instead of the create action. Why isn't the POST getting routed to the create action as it should (being RESTful)? routes.rb: map.namespace :admin do |admin| admin.resources :events ...

How do I access a nested model from view?

I have a drop down like this on my page: <p> <%= f.label :episode_id %><br /> <%= f.collection_select(:episode_id, @episodes, :id, :show) %> </p> An episode has an id and belongs_to to a show which has a name. In the dropdown, I'd like to display the show name. :show.name doesn't work to display the name. How do I do this...

Selenium: wait_for_* and friends in Selenium RC ruby driver

Are there any implementations of all the nifty Selenium on Rails methods like wait_for_visible, assert_not_text_present, ... for the ruby driver of Selenium RC? If not, how would I go about implementing something like wait_for_visible? ...

Preferred fixture replacement plugin in Rails?

There are a dozen Rails plugins whose goal is to replace fixtures in testing. Here are a few I can think of: fixture replacement factory girl factories and workers rails scenarios fixture-scenarios object daddy There are probably others. Which of these plugins do you prefer and why? ...