ruby-on-rails

Rails application starts with wrong rails version

I'm trying to upgrade a Rails 2 application to Rails 3. rails -v outputs Rails 3.0.0.rc -- so, that part's good. But... When I do: rails server I just get the help So I tried script/server and I get: => Booting WEBrick => Rails 2.3.2 application starting on http://0.0.0.0:3000 I've done a global replace in the application...

Array.count works fine locally but breaks on heroku

Right now, if I go to the index action of a model that I have, I don't show the basic table of data that rails generates for me if there are no existing records in the database. I do something like: <% if @my_records.count > 0 %> <table> <tr> <th>...</th> <th>...</th> <th>...</th> <th>etc</th> </tr> <% @my_records....

Sending XML over HTTP with Rails

I am dealing with a third-party api here and I need to send HTTP Post request represented in XML. How should I go about doing this in Rails? Which library/method if any will allow me to do this? ...

How to call ActiveSupport method inside rake task?

This is what I'm trying: require "active_support" desc "test" task :foo => [:environment] do parse(:categories) do |hash| # cleanup name hash[:name] = titlecase(hash[:name]) # ... end end This is the error I'm getting: undefined method `titlecase' main:Object I've also tried: ActiveSupport::Inflector::titlecase...

"no such file to load -- memcached" problem

Hi, I'm playing with one open source project and have a problem with the "memcached". Actually I get a "no such file to load -- memcached" error when I do a "rake db:migrate". It appears to me that I should install it somehow, but unfortunately a "gem install memcached" drops a error. This is my console log: D:\BitNami RubyStack proje...

[rails] Elegant way to perform polling while user is waiting in real time

What is an elegant way to perform polling while the user is waiting? This is what i mean: 1) User clicks a bottom 2) Server performs an action that might take a few minutes 3) Want the page to constantly poll the server for updates 4) if not ready, returns back a status message with updates, if ready, show time taken Did you have any ...

Regular expression not working when put in an object

Hi! I'm trying to store regexes in a database but they're not working when used in a .sub(), even though the same regex works when used directly in .sub() as a string. regex = Class.object.field // Class.object is an active record containing "\w*\s\/\s" mystring = "first / second" mystring.sub(/#{regex}/, '') // => nil mystring.sub(...

cURL to PHP is as [blank] to Ruby(Rails)

Anyone knows the Ruby's counterpart of cURL? I am trying to send XML through HTTP POST but I keep getting Bad Request and Unauthorized. I saw the sample source code in PHP and saw that the sample code uses cURL to do this. ...

How can I add create/edit models feature on the model index page?

Ok, I have a model that is very simple: ServiceType(id: integer, title: string, duration: integer, created_at: datetime, updated_at: datetime) Because its so simple, It's ridiculous that I should have a separate page for creating and updating those types of records. What I would like to do is have a form on my index page which I can u...

How do I add a strategy to Devise

I'm trying to add a really simple strategy to devise, and it doesn't seem to be working. Here is the code that I am trying to use #config/initializers/devise.rb Devise.setup do |config| config.orm = :mongo_mapper config.warden do |manager| manager.strategies.add(:auto_login_strategy) do def valid? params[:auto_l...

How to speed up single (last) migration test?

I'm writing my migration SQL against tests. Because the migration is the last one and we've got about 300 migrations, it's DAMN SLOW to get there, as it migrates from bottom up every time. Any ideas how to speed this up a bit? ...

CSS on PDF (Prawn)

Hi, Can we use stylesheet classes inside Pdf reports? i am trying to change the header_color from b7e3fe to .heading oh the stylesheet, inside the table file:heading.pdf.prawn texts=[""],[""] pdf.table texts, :headers => [" Heading "], :header_color => 'b7e3fe', file: public/stylesheets/style.css .heading { font-famil...

How to keep "Cached Values" in Sync in MongoMapper-Model?

Hi together, at the moment I'm doing some tests with MongoMapper. When using relations, http://www.mongodb.org/display/DOCS/MongoDB+Data+Modeling+and+Rails sugests to use cached values where it fits... I take a stripped down example from there: class Story include MongoMapper::Document key :title, String key :url, Str...

ActiveRecord association not found - but only on second load

Hi All, I recently upgraded from Rails 2.0.2 to 2.3.8 and have been ironing out the kinks. This one is baffling me. I have a page that runs fine in production, but in development mode it runs fine on first load, then on reload it crashes with: ActiveRecord::ConfigurationError - Association named 'average_prices' was not found; per...

Sorting by calculated value with Rails

Hi I am currently sorting a data table in a Rails 2.3 application by various different columns using the sortable_column_headers plugin. This works great and I can sort columns on the current model or easily on associated models too. My problem though is one column in the table is a calculated value (it's the result of divising one co...

RVM do not recognize system's ruby version

Hello, I am running ruby 1.8.7 (2009-12-24 patchlevel 248) on my fedora 13 machine. Now i want to try out ruby 1.9.2 so I installed RVM (rvm 1.0.1 by Wayne E. Seguin). I want RVM to know my system's ruby, but unfortunately when I run "rvm list" it doesn't list any rubies. How can I make rvm recognize hence switch between system's and r...

RoR reload page after closing thickbox

hi, how can we code for reloading page after closing thick box. thanks ...

Linux box hosting in HK?

Hi all, Anyone has done linux hosting on hong kong based hosting? I have the following requirements for my rails application. Must have static IP. Root access The application/site is just started and don't have much traffic yet. ...

Is there any setting required to be done before unit testing a model that maps to a different table as compared to Rails convention?

I have a model Vehicle which actually maps to the at_vehicles table. So while running my test script for Vehicle, I get the error "'vehicles' relation does not exist". Is there a hack , that could allow me to run my tests with the current db schema as is? Thanks. ...

RoR: How to handle custom nested form's submit

Hello! I managed to do almost all the way towards happiness with my custom form in ruby-on-rails, but the very last step is missing and it is impossible to find the answer on the net because of too many common words. I believe that the answers to my questions are trivial for people who have done RoR for a time, but be warned that the p...