ruby-on-rails

Is there an advantage to running JRuby if you don't know any Java?

I've heard great things about JRuby and I know you can run it without knowing any Java. My development skills are strong, Java is just not one of the tools I know. It's a massive tool with a myriad of accompanying tools such as Maven/Ant/JUnit etc. Is it worth moving my current Rails applications to JRuby for performance reasons alone? ...

How to use ActiveRecord Query Cache with Custom SQL

In a stats part of a Rails app, I have some custom SQL calls that are called with ActiveRecord::Base.execute() from the model code. They return various aggregates. Some of these (identical) queries are run in a loop in the controller, and it seems that they aren't cached by the ActiveRecord query cache. Is there any way to cache custom...

ActiveModel::Naming attributes definition

Dear all, I'm working on a rails3 app and I'm a little bit confused with Active Model. Here is my model : class MyClass include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_accessor :foo, :foo1, foo2 def initialize(attributes = {}) attributes.each { |key, value| send "#{key}=", va...

What are some alternatives to using Tomcat for Jruby Rack apps??

We're looking at some alternatives to our Tomcat based stack for a JRuby on Rails app. So far I've read about the Trinidad gem, which is actually Tomcat based, and the Glassfish gem. I can't however for either of these find production examples. Both of them it seems allow you to just run the command on command line, which is fine fo...

Is fb_graph or Koala gem better than facebooker2?

Is the fb_graph gem better? It seems to be newer, but the facebooker has a lot more people using. http://github.com/nsanta/fbgraph http://github.com/mmangino/facebooker Update: I looked into koala, and it seems it is a good choice as well. http://github.com/arsduo/koala I also figure out that fb_graph is different than fbgraph. ...

In Ruby on Rails, what's the difference between DateTime, Timestamp, Time and Date?

In my experience, getting dates/times right when programming is always fraught with danger and difficulity. Ruby and Rails have always eluded me on this one, if only due to the overwhelming number of options; I never have any idea which I should pick. When I'm using Rails and looking at ActiveRecord datatypes I can find the following ...

Creating a nested remote_form within a regular form

I'm trying to create a nested remote_form within another non-remote form in one of my RoR apps. It looks likes this: form_for @event do |f| f.text_field :name remote_form_for @location do |d| d.text_field :address d.submit f.text_area :another f.submit end Of course it's more complicated than this, but...

Ruby on Rails, update div on click with link_to_remote

I'm implementing a netflix-like 5 star review ratings. The goal is to have a "rating" div that serves both to enter the rating by clicking on one of the stars, as well to display the current rating. I want to update the "rating" after a users enters a new rating. For now, I can add a rating and create the association to the rated asset,...

jQuery call for a partial doesn't work if there is RoR code in it?

Hi, I am trying to get paginating to work with jQeury. I am using the will_paginate gem. It works normally (with no javascript). I tried following a railscast (http://railscasts.com/episodes/174-pagination-with-ajax) but I am still having a problem. show.js.erb $('#comments').html("<%= escape_javascript(render "comments/comment.html.e...

set default_url_options on initialize

I need to force the host in one of the environments in my rails app. I've can get the override to work by including def default_url_options(opts={}) opts.merge({:host => 'stg.my-host.com'}) end in app/controllers/application.rb But is there a way to set this on initialize, preferably in a config/environments/... file? I'd li...

issue with factory_girl , rpsec 2.0 and rails 3.0 => can't get has_one relation working nicely together!

I'm running rails 3.0, rspec 2.0 and factory_girl. Here is the simplified scenario I'm working with: a user can subscribe to only one plan at a time # user.rb class User < ActiveRecord::Base has_one :plan attr_accessible :login, :plan_id end # plan.rb class Profile < ActiveRecord::Base attr_accessible :plan end # user_factory.rb...

Is Rails making too many SQL queries behind the scenes for my simple average ratings cache?

I have a ShowRating model which keeps a log of every show rated on by a user and have been keeping an average rating and ratings count cached inside my Show model, so I can access it in the show controller without rebuilding this data on the fly. I've been keeping an eye on the SQL queries executed and I'm curious about why Rails chose t...

Pass instance or local variable from layout to view in Rails

I'm trying to set up a rather complex form using form_for. This form needs to be in multiple views, where some fields would be available across all actions and other fields are specific to each individual actions. I thought that in order to save myself code duplication, I would use a layout to render the general part, like this: # layo...

Resize Image in rails on serve

Hi, I'm making a application with ruby on rails and I was wondering if anyone knew of a gem or plugin to resize images as they are served similar to http://shiftingpixel.com/2008/03/03/smart-image-resizer/ Thanks. ...

filtering links in rails

Is there a way to filter out links posted in a comment or in a form. The datatype of the column where the field is stored might be text or varchar. I essentially want to strip off any kind of url embedded witin the content. ...

I want to optimise the upload of a file onto the server - whats the best way to do it?

Hi all, I have a rails app that does the following (at the moment linear) process: (1) User uploads a file via HTTP and a standard upload form on a standard HTML page (2) The file is uploaded to an apache server (same server as the one hosting the app) (3) The server uploads the file to remote storage service (call this storage 1) (4) ...

Custom cropping in Rails with Paperclip

I'm currently using Paperclip to upload an image and automatically generate a thumbnail. Now I would also like to add a second style that generates a one-pixel-wide image using the left-most column of pixels in the uploaded image (it should also have the same height as the original image). I'll be using the one-pixel-wide image as a repe...

How to create a new database from within a Rails app?

Hi all, I'm working on a Rails app that has one database per account. (I know this is a controversial approach in itself, but I'm confident it's the right one in this case.) I'd like to automate entirely the process of creating a new user account, which means I need to be able create a new database and populate it with some seed data ...

Ruby MySQL gem on Snow Leopard "couldn't create database" error

The environment: Mac OS X 10.6.4 $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] $ rails -v Rails 2.3.9 $ mysql --version mysql Ver 14.14 Distrib 5.1.51, for apple-darwin10.3.0 (i386) using readline 5.1 $ gem environment RubyGems Environment: - RUBYGEMS VERSION: 1.3.7 - RUBY VERSION: 1.8.7 (2009-06-12 pa...

Do you do this in every step definition ? "Given that I am logged in"

I am new to cucumber. And for most of the site's functionality, you have to be logged in. So when writing cucumber, do you write, given that I am logged in for every step definition? ...