ruby-on-rails

Integrating "really simple history" with Rails

In trying to solve the "ajax back button" problem I have found the Really Simply History library. Has anyone tried to integrate it with Rails? It's plain old javascript so it seems like it should integrate just fine, but I know next to nothing about JS itself, so I'm not too confident in trying to do the integration without a tutorial...

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...

How do you write a case insensitive query for both mySQL and postgres?

I'm running a mySQL database locally for development, but deploying to Heroku which uses postgres. Heroku handles almost everything, except that my case insensitive Like statements become case sensitive. I know I could use iLike statements, but my local mySQL database can't handle that. What is the best way to write a case insensitive q...

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...

Someone can look at the syntax of my rakefile?

I'm trying to write an import rakefile for Redmine. It uses ruby on rails. I'm not a rails developer but we do like using redmine for project and issues management. require 'rubygmes' require 'fastercsv' # csv issues import for redmine # Will convert a csv into a issues bulkloader into redmine # Column names # row[0]=Nb Number,row[1]=P...

rails - link_to_remote versus render

Is it possible to reload a page that was loaded thru link_to_remote? I'm doing this in my controller: def create if captchas_verified do_something else render :action=>'new' end But when the captchas is wrong, it do not render a form that is inside of the new template. By the way, in the webserver log, it shows that the templad...

Rails: Best way to make changes to a production database

I need to make changes to an in-use production database. Just adding a few columns. I've made the changes to the dev database with migrations. What is the best way to update the production database while preserving the existing data and not disrupting operation too much? It's MYSQL and I will be needing to add data to the columns as ...

What's your favorite Prototype framework compatible, javascript date picker?

Please one library per answer so that people can vote for the individually. ...

Rails x FastCGI

Should i stay out of rails if a client has a cheap hosting service with a provider that do not support mod_rails? Will rails + fast.cgi provide a good experience for a user or should I choose, in this scenario, php + my-favorite-framework as platform ? Regards, Victor ...

Need a book on rails - does it need to cover 2.0?

This is similar to a previous question on Rails Books, but I'm looking for a little more detail on something that was brought up in that thread. I'm starting a project using Rails 2.0 next week, and I'd like a book to read to get going. Dead-tree format is a must, this is for the bus. Agile Web Development with Rails seems to be the ...

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...

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...

Organisation of routes in Rails -- restful_authentication, session and /login

I am struggling with the route setup for a Rails application. I have installed restful_authentication and mostly followed the instructions. I have set up the routes this way: map.login '/login', :controller => 'sessions', :action => 'new' map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.resource :session If yo...

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? ...

Rails and CouchDB - Architectural Concerns

I am working on a project that is going to use CouchDB for flexible storage of documents. The requirements of my system are a neat match for CouchDB for storage. BUT My question really boils down to this: Should I keeop using ActiveRecord and MySQL as well ... there are a raft of handy Plugins that are all readily available for use wit...

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? ...

Creating routes with an optional path prefix

How can I go about making my routes recognise an optional prefix parameter as follows: /*lang/controller/id In that the lang part is optional, and has a default value if it's not specified in the URL: /en/posts/1 => lang = en /fr/posts/1 => lang = fr /posts/1 => lang = en EDIT Ideally, I'm looking to do this across many c...