ruby-on-rails

Best way to get started with Facebook and Ruby on Rails

I'm looking to develop my first Facebook application and therefore looking for some advice on where to get started. I've spent a few hours browsing Facebook's Developer Wiki, Facebooker library, looking at the sample chapters in "Developing Facebook Applications with Rails" by Pragmatic Programmers, etc. Since FB is constantly changin...

Rails activerecord to_sql_string?

I've seen somewhere but can not remember. How to get a SQL string from an ActiveRecord object? Client.find(1).to_sql_string ...

Ruby on Rails associations for set theory (union, difference, intersection, etc.)

I would like a has_many association that works like so: class Hood acts_as_tree has_many :houses, :union_with => :parent end class House end where any House associated with Hood 1 would also be returned in .houses of subhoods of Hood 1, along with the subhoods' individual associations. The association only needs to work from the...

What is the difference between a restful route method for getting an index vs. creating a new object?

According to rake routes, there's the same path for getting an index of objects as there is for creating a new object: cars GET /cars(.:format) {:controller=>"plugs", :what=>"car", :action=>"index"} POST /cars(.:format) {:controller=>"plugs", :what=>"car", :action=>"create"} Obviously, the HTTP verb is what distinguish...

Rails custom db table

My app is sending messages to client groups. I send message to each client in a loop. I'm using 3 ActiveRecord models: class Message < AbstractBase has_and_belongs_to_many :groups end class Client < ActiveRecord::Base has_and_belongs_to_many :groups end class Group < ActiveRecord::Base has_and_belongs_to_many :messages has_an...

Splitting PDF to png

I'm using paperclip to upload a pdf. Once the file is uploaded I need to split every page into a png. This is the command I think I need to use convert -size 640x300 fileName.pdf slide.png Now if I run that command from terminal it works fine, but I need a way of getting each slides name so I can add it into a model. What's the best w...

How do I make a grouped select box grouped by a column for a given model in Formtastic for Rails?

In my Rails project I'm using Formtastic to manage my forms. I have a model, Tags, with a column, "group". The group column is just a simple hardcoded way to organize my tags. I will post my Tag model class so you can see how it's organized class Tag < ActiveRecord::Base class Group BRAND = 1 SEASON = 2 OCCASION = ...

adding model validation errors in rescue

I have the following model with a virtual attribute class Mytimeperiod < ActiveRecord::Base validates presence of :from_dt validates_format_of :from_dt, :with => /\A\d{2}\/\d{2}\/\d{4}\Z/, :message => "format is mm/dd/yyyy" def from_dt self.from_date.strftime("%m/%d/%Y") if !self.from_date.blank? end def from_dt=(from_...

How do you use ARel's #as method?

If you build a projection like this: t = Arel::Table.new(:projects) ps = t.project(t[:id].as(:snark)) How do you get the result column that's named :snark? ...

Where are some current Ruby & RoR resources?

Hello, I've been a PHP Developer for a few years now and I've recently been interested in learning Ruby & Rails but I've found a lot of the resources I've found seem to be dated and not for Rails 2.0 or Ruby 1.8.6 etc... can anyone point me in the right direction? I'm running OSX 10.6 with the default ruby & rails installation. Thanks!...

Rails Sessions current practices (especially for rails 3)

Anyone have any "best practices" tips for Rails and sessions? The default session type for Rails3 is still cookie store, right? I used SqlSessionStore for a while and it worked well, but I may move away from that in favor of CookieStore. Is it still not a good idea to use CookieStore for sensitive info, even with salted info or is that...

Can you in any way interface Ruby Gems with PHP, Python, etc.?

Stupid question, and forgive me for asking, but someone is asking me, and I am not a super expert with Rails yet. Suppose I have some Rails gem I write. Now suppose a customer has some other framework, like Django or CakePHP, and I want to provide the functionality offered by my gem (eg. CRUD for automotive data) to them as a module in ...

SQL Server Trouble with Rails

Ok, I've been trying to get this to work like all day now and I'm barely any further from when I started. I'm trying to get Ruby On Rails to connect to SQL Server. I've installed unixODBC and configured it and FreeTDS and installed just about every Ruby gem relating to ODBC that exists. (This has been updated to show the output of isq...

Are ActiveRecord:Observer callbacks called during unit testing?

I'm trying to unit test an observer in rails but none of its callbacks are being invoked. I'm sure I have something configured incorrectly but just to be sure I was wondering if this may be a Rails limitation during unit testing. I've looked at the docs and they don't mention anything. ...

How to define a constant when running script/server?

I want to start up my Rails development server like this: script/server OFFLINE_MODE=1 and have a method in application_controller.rb that checks for the presence of that constant: helper_method :offline_mode? def offline_mode? defined?(OFFLINE_MODE) ? true : false end so I can hide stuff in my app when I'm coding without access ...

Help installing delayed_job

I'm trying to use collectiveidea's delayed_job gem The installation instructions include Rake tasks are not automatically loaded from gems, so you’ll need to add the following to your Rakefile: begin require 'delayed/tasks' rescue LoadError STDERR.puts "Run `rake gems:install` to install delayed_job" end Where is my Rakefile? And...

How do I display the validation which failed in my Rails unit test?

Summary: Failed unit tests tell me which assert (file:line) failed, but not which validation resulted in the failure. More info: I have 11 validations in one of my models. Unit testing is great, whether I run `rake test:units --trace' or 'ruby -Itest test/unit/mymodel_test.rb'. However, despite the fact that it tells me exactly which ...

Does Rails need database-level constraints?

I have the same problem as in the following post. So I am wondering, why doesn't Rails support generating foreign keys by default? Isn't it necessary? Or are we supposed to do it manually? ...

Spork servers super slow (>3m) to start for RSpec & Cucumber BDD

I recently installed a fresh development setup on my laptop and now notice that my instances of spork take several minutes to start up. This is also most likely of the RSpec and Cucumber tests start up times running super slow. I ran in diagnostic mode with the -d flag and received the output below. Anyone have a clue why this is sudd...

Is reading xml simple in rails or converting it to hash will be simpler?

Hi All, Sorry for this question but after spending 1-2 hours on how to read xml, i thought posting it on forum will be better. So i get a complex (very large)xml response from the plugin trackify. i want to read some values from it so i convert it into hash and then read it as follows For ex:- to read city @tracking_info['TrackResponse...