ruby-on-rails

What does ActiveRecord::Base.connection.execute return in Rails?

Hi, I want to run a raw SQL query as following: ActiveRecord::Base.connection.execute(some_query); Can I capture any errors that happen while executing the query? If yes, how? Does execute returns anything? It doesn't say in the documentation. Cheers ...

Best way to return array of counted values for multiple date ranges in Rails

I'm trying to return an array of counted values for consecutive date ranges (that will vary in distance), so that I have something like the following: counted_values = [2,0,4,5,6,0,0,4,2] So far I've written something that works but makes me shudder slightly, as I'm sure there's a more Rubyist/Rails way of doing it. Current code: ...

I feel like this needs to be refactored - any help? Ruby modeling

So let's say you have line_items and line_items belong to a make and a model a make has many models and line items a model belongs to a make For the bare example idea LineItem.new(:make => "Apple", :model => "Mac Book Pro") When creating a LinteItem you want a text_field box for a make and a model. Makes and models shouldn't exist...

virtual column for drop down in the ruby on rails.

How to place a drop down for the virtual column, in the ruby on rails. The virutal column does not exist in my table , but I want to get the value from the drop down ,when user saves the data. for example, product_price is a virtual column , which doesn't exist in my database table. But I would like to have a dropdown, with product pr...

Rails association for two foreign keys for the same table in one table

I am new to RoR and still playing with associations. I need to have two references to a particular model in another model. The scaffolded code doesn't work and I get a "uninitialized constant" error. Generation commands: script/generate scaffold BaseModel name:string script/generate scaffold NewModel name:string base1:references base2:...

How to make this concept RESTful?

I have a controller dealing with sending SMS Messages, and it's set up as a default resource. Now, business requirements have changed and we want to offer the user three different ways of sending the message: To everybody on their contact list To a segmented portion of their contact list (predefined) To individual contacts that they c...

Capistrano: deploy.rb file refactoring

I have following code in my deploy.rb namespace :app do desc "copies the configuration frile from ~/shared/config/*.yml to ~/config" task :copy_config_files,:roles => :app do run "cp -fv #{deploy_to}/shared/config/hoptoad.rb #{release_path}/config/initializers" run "cp -fv #{deploy_to}/shared/config/app_config.yml #{release_...

Thinking Sphinx - Foreign key with different type - Association problem

Hello, I have two tables on mysql: users, and management. The users table has a numeric id, and the management table has a varchar foreign key which is the primary key of the other table. The types are not the same, and this seems to be the main problem when I build an index from the User model, and try to include one column from the ma...

How could I justify text in a text_box in Prawn?

Is there a way to justify text in pdf.text_box using the prawn plugin? ...

Ruby on Rails link_to internal id

How do i use a link_to inorder to go to a specific (html) ID on a page normally if i wanted to go to the "whatever_id" on a page i could use <a href="http://www.example.com/index/mypage#whatever_id&gt;Click Here</a> but i would like to use my link_to <%= link_to "click here" , {:action => "mypage", :controller => "index" }, :id => "...

Rails XML Builder: How do I in-explicitly construct XML elements?

I am trying to use xml builder without explicit definition of elements. This is useful when the required elements are variant. How can I accomplish something similar to the following? xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" for col in [:customer, :name, :address, :city, :street, :postal_code] eval("xml.#{col.to_s....

Best way to combine and minify JS / CSS on Heroku

First of all, according to this answer, the :cache => true option on stylesheet_link_tag and javascript_include_tag doesn't work on Heroku. Is this true? I've found :cache => true to work occasionally, but not always (weird!) Also, what's the best solution here? Ideally it would seamlessly combine and minify all CSS / JS. Heroku Asset ...

Recommendation needed: Rails, Postgres and fuzzy full text search

I have Rails app with a Postgres backend. I need to add full text search which would allow fuzzy searches based on Levenshtein distance or other similar metrics. Add the fact that the lexer/stemmer has to work with non-English words (it would be ok to just switch language-dependent features off when lexing, to not mess with the target l...

Single Account for Multiple Application login in Rails

Hello, I'm building some applications using rails. All apps using restful auth plugin for User base and declarative authorization plugin for authorization rules. But I need to merge all site's User accounts to one User base for providing login for all sites. I.e like 37signals working on. Here is their work ; http://37signals.com/...

Should I give up on deploying Rails under Windows?

I run an instance of a rails application that is developed by another team. Back when I started, the common way to deploy Rails apps was to use Mongrel behind Apache, and that's the configuration that that team used for their own instances. Since I'm a Windows guy, and since both Apache and Mongrel can easily be set up as Windows service...

How do you access an instance variable in an Authlogic config block?

Given a user model something along the lines of: class User < ActiveRecord::Base acts_as_authentic do |config| config.validate_email_field = true end end I would like to be able to modify "true" to be specific to the user that is signing up. I would like to be able to do something like: class User < ActiveRecord::Base ac...

RoR: View and Controller subdirectories?

I'm trying to use this technique (http://blog.hasmanythrough.com/2008/4/2/simple-pages) on "boiler-plate" pages I want to keep in a subdirectory of my controller's view folder. How would I do this? The below doesn't seem to work: returns a "Template missing" error. Error: Missing template home/New_York_apartments.erb in view path app...

how to prepare for a Ruby interview in just one weekend

I'm a seasoned web developer but only have a modicum of Ruby/Rails experience. I just got an interview Monday at a Ruby shop, they do realize I don't have much Ruby experience. Besides 2 or 3 Ruby books I have lying around, what other resources might I avail myself of for a weekend crash course in Ruby. I do have a bare minimum accoun...

Combining many rake tasks into one rake task

Instead of running each rake task individually like this: rake db:drop rake db:create rake db:migrate rake db:load I want to run one rake task that does all for. This is what I have for my rakefile: desc 'This rebuilds development db' namespace :rebuild_dev do Rake::Task["db:drop"].execute Rake::Task["db:create"].execute Rake::Ta...

Rails fake deletion of a row

I'm looking for a way to faux-delete rows from a table using Rails. The rows shouldn't show up in any normal .find() search except for when I want to show recently deleted items. I'm using an Activities table right now for management of such tasks, which stores the class, id and method performed on rows recently. Is there a way to disab...