ruby-on-rails

Ruby: If I wanted to convert order.price to a decimal value, do I use order.price.to_i?

Very beginner's question: I noticed that there's no .to_d (such as order.price.to_d to convert order.price into a decimal). Say order.price is currently a string; can I then use order.price.to_i to convert it into a decimal? ...

How might you clone a database table via Rails migration?

I want a migration to create a clone of an existing table by just suffixing the name, including all the indexes from the original table. So there's a "snapshots" table and I want to create "snapshots_temp" as an exact copy of the table (not the data, just the table schema, but including the indexes). I could just copy and paste the b...

missing rails gem: zlib not found on snow leopard, but shows in ports

Trying to start development on a snow leopard machine. Have reinstalled and built ruby and ruby on rails via hivelogic post Prior to sorting out my own rails app, I created a test app, and all the expected files showed up. But when I try to run it I get Missing the Rails 2.2.2 gem. Please gem install -v=2.2.2 rails, update your RA...

mod_rails and Paperclip problem Paperclip::NotIdentifiedByImageMagickError

Hello, I am havingn troble deploying my app to a server runing ubuntu with mod_rails. Runing webrick on the server seems fine and I can save files, no problem. But runing the app thru nginx, I get this error when I try to save a file. [paperclip] An error was received while processing: # [paperclip] An error was received while processi...

Force download of file in the public directory from a controller action?

I've done this: <% response.headers['Content-Disposition'] = "attachment; filename=somefile.txt" -%> I am a text file! I'd like to force the download of a file in my public folder without revealing the path, so I've got a controller than checks some params to know the location of my file (in my public folder) and then I'd li...

Rails ActiveRecord fetch records with appropriate data types

Hi, I am using Ruby, I want data in array of hash format. I have tried out ActiveRecord's select_al method. But it returns all the data in string format, does not matter what type is its type in data base. All numbers are also returned in string format. Please, give your valuable suggestions. Thank you all for your precious time. T...

Large RoR project migration from Ruby 1.8.6 to 1.8.7+ solution

Hello! After updating to Snow Leopard, Ruby 1.8.7 (preinstalled with OS) become much more closer to me. I try to use port's but has no luck with this solution. (port ryby186 halt something without drop exception). So I start to think about update large scope of code to 1.8.7 requirements. Please help me with some scripts, articles and s...

ActiveRecord-JDBC is for use with JRuby only problem

I'm running ruby script/server from the command line and getting ActiveRecord-JDBC is for use with JRuby only it then suggests gem install activerecord-jdbcmysql-adapter but when I try this it says that (no such file to load -- java) (RuntimeError) I've tried a fresh install of Rails and reinstalling the gems, but still not joy. A...

Why is link_to adding an id to its output when I don't pass a model id?

I'm using Rails 2.2.2 with the old school routes (i.e. I'm not being RESTful) and I'm noticing strange behavior coming from the Rails link_to method. Here is my call: link_to("my description", { :controller => controller, :action => action }, :id => "html_id") I want the method to produce "/controller/action" but instead I'm getting "...

Ruby on Rails drag and drop won't work

Hi, I am trying to create a Ruby on rails application using the integrated scriptaculous drag and drop effect. Since I'm new to the ruby language I ended up with this code while viewing many documentation but can't understand why the controller code is not executed. In the html.erb page the origin div <% for therm in @therms %> ...

Test::Unit tests passing on OS X, erroring out on CentOS

I have a set of Test::Unit tests for a Rails application. It was developed on OS X under Ruby 1.8.6, Rails 2.3.4. I'm also using thoughtbot-shoulda 2.10.2. I'm using standard Rails fixtures, not factories. I've checked out the project onto a CentOS Linux 5 workstation for another developer to work on. He's running Ruby 1.8.7. (The ap...

How do I route common named controllers by subdomain in rails

I am trying to figure out how to successfully use the same controller name in the URL, but route different controllers. Dependant on the existence of a subdomain. Example. http://www.mysite.com/pages/1 Routes to the SitePages Controller http://anyothersubdomain.mysite.com/pages/1 Routes to the UserPages Controller Up until now, I ha...

Can't see the source of an error in Rails

I'm trying to locate a bug (in my dev environment) that is preventing a successful form submission. Instead of the usual helpful error screen I'm used to seeing, I'm getting an unhelpful 404 screen. Tailing development.log shows me nothing except the parameters sent with the form and that the response was a 404. How can I see what's rea...

Removing the :has_many when the :belongs_to is updated/destroyed if the :has_many is now empty

I have states who have many cities (belongs_to :state) who have many businesses (belongs_to :city). State also… has_many :businesses, :through => :cities On my site everything is managed from the Business perspective. When a new Business is created/updated the state/city is created if it doesn't already exist. This happens in a :before_...

Can't get Ruby ODBC bindings to work in 1.8.6 compiled on snow leopard

I have been trying to get ruby 1.8.6 to connect to a MS SQL Server 2005 on Mac OS X snow leopard following the guide here http://wiki.rubyonrails.org/database-support/ms-sql. I have installed the Ruby ODBC Bindings and the dbi and dbd-odbc gems and ruby was compiled from source. If I run this in irb, DBI.connect('dbi:ODBC:A_DSN', '...

When to use Mongrel as web server for Rails application?

When I started my first bigger Rails application, I chose to use Apache (with Passenger), because I already had some experience with it with PHP, but I don't have any deep knowledge of deploying Rails applications. How would one choose web server for a Rails app? Are there any main differences between Apache and Mongrel? Or is it just ...

How to check the cause for a HTTP request latency/waiting time?

I issue a simple GET request to my server, and it's coming back after ~1.2 seconds on average (using firebug NET tab, the "waiting for reqponse" part- not even the whole reponse time) My ping to the server is 0.250 Using Passenger with rails 2.3.3, in the rails log the request is taking ~0.023 My server is on GoDaddy, so I checked the...

Rails Authorization Plugin Error

I'm trying to get the permit method to work using the rails-authorization-plugin and authlogic, and I keep running into this error: When I try: class ApplicationController < ActionController::Base ... before_filter permit 'admin' ... I get this: Authorization::CannotObtainUserObject in HomeController#index Couldn't find #curre...

rails ajax and partials

I cant get a partial to iterate- the object I pass never matches the partial variables The controller method for the ajax def news @fixture = Fixture.find(params[:fixture_id]) home_team = Team.find(@fixture.home_team) away_team = Team.find(@fixture.away_team) @story = Story.find(:all, :conditions => "team_id = #{home_team.id}...

Paperclip S3 buckets, proc and environments

From reading the documentation I understand this might be doable, but I don't know how! For the production environment I have three buckets (three models, three buckets) image-bucket, audio-bucket, pdf-bucket, but for the development environment, I want to have dev-image-bucket, dev-audio-bucket, dev-pdf-bucket. How do I set the proc?...