ruby-on-rails

Development workflow for Heroku?

I have used Heroku to push up my already coded Rails applications. But now I wonder how the workflow would look like if I start coding a new Rails application from scratch. For example if I use their addons (MongoHQ, Redis, Websolr, Sendgrid etc) in my application code, then I guess I shouldn't install MongoDB, Redis, Solr, Mail server...

Is there easy way to search in fetched records?

So, I want to search in fetched records: p = Product.added_today # Get records by scope # wants something like p.search(:name => 'Clocks') Is there easy (rails way) to do it (gem or something)? ...

Alternative for ssl_requirement plugin for Rails 3?

I have used ssl_requirement plugin for previous versions of Rails and it is awesome. But for Rails 3 I want to try out some new plugins or gems. Any suggestions? ...

How do I have two home pages, one for logged in users and one for everyone else, both at the root path?

I have a Pages controller, with an action/view called home. I have set this as the root of the site with map.root :controller => "pages", :action => "home" At the moment, I am using this page as part of the logged in user's workflow, thus it is required for the user to be logged in to see it. But I also need the root path to serve as...

How to setup Google Apps with ActionMailer with Rails 2.3.5?

I've got Google Apps setup with email for my domain, and now I need to configure ActionMailer to use it. But the info I've found seems to be conflicting. Can anyone tell me how exactly to set it up with Rails 2.3.5? ...

Postgres adapter error after gems:unpack

I have installed following gems: actionmailer (2.3.8) actionpack (2.3.8) activerecord (2.3.8) activeresource (2.3.8) activesupport (2.3.8) open4 (1.0.1) pg (0.9.0) rack (1.1.0) rails (2.3.8) rake (0.8.7) My application uses postgres as db and pg gem and it had been working fine by the time I done rake rails:freeze:gems rake gems:un...

I get this same error everytime I try to run rake db:migrate on a cloned project from Github

Everything I clone a project on Github and then run rake db:migrate, I get this error (project name is mini_fb_demo): $ git clone http://github.com/appoxy/mini_fb_demo.git Initialized empty Git repository in /Users/ben/rails_projects/mini_fb_demo/.git/ remote: Counting objects: 102, done. remote: Compressing objects: 100% (91/91), done....

ActiveRecord Global Callbacks for all Models

Hi All, I have around 40 models in my RoR application. I want to setup a after_save callback for all models. One way is to add it to all models. Since this callback has the same code to run, is there a way to define it globally once so that it gets invoked for all models. I tried this with no luck: class ActiveRecord::Base after_s...

Permission denied when running script/server

I just cloned the mini_fb_demo from Github, went into the directory and ran script/server, and got this error: -bash: script/server: Permission denied I've been using script/server like this for other projects for awhile, and this has never happened. What is causing this? Thanks for reading. ...

How to use a variable as object attribute in rails?

I have a PaymentDetail model with attribute 'home_address_country', so i can use @payment_detail.home_address_country //where @payment_detail is object of that model. I want to use something like this:--- country_attribute=address_type+"_address_country" //where address type is equal to 'home' @payment_detail."#{country_attribu...

How to set the column_width for table while using rails prawn???

This is my prwan code table1 = [["Time duration selected", "Driving Time", "Stop Time", "Productivity", "Stop Count", "Max Speed (km/h)", "Average Speed (km/h)", "Distance Travelled (km)"]] table(table1) This code creates a row.. But i need to specify column width here... so how to set the column width? ...

Using the URL option in a form_for

I have a form with a url option. - form_for [@organization, @video], :url => organization_media_videos_with_session_path(@organization), :html => { :multipart => true } do |f| That URL is specifically a helper that I wrote here : def organization_media_videos_with_session_path(organization) session_key = ActionController::Base.sess...

Ruby on Rails: check the amount of products a shop owns

I'm messing around with a test/exercise project just to understand Rails better. In my case I have three models: Shop, User and Product. A Shop can be of three types: basic, medium, large. Basic can have 10 Products maximum, medium 50, large 100. I'm trying to validate this kind of data, the type of Shop and check how many products it...

Common refactoring pattern for Rails model.

Is there a pattern to refactor such a construct into a readable single line? def show_section @news = News.all_active @news = @news.where(:section => params[:section]) unless params[:section] == "all" @news = @news.all end I use Rails 3 and Ruby 1.9.2 ...

bundle: command not found

I'm hosting on a vps,ubuntu 10.04, rails3, ruby and mysql installed correctly by following tutorials. If I run 'bundle check' or 'bundle install' I get the error '-bash: bundle: command not found'. From 'gem list --local' I see 'bundler (1.0.2, 1.0.0)' is installed. I don't know what's going wrong... gem environment returns: RubyGems...

Adding custom shoulda matchers to TestCase

After using shoulda it is very clear that shoulda no longer uses macros (They are all deprecated for the preferred matchers) For example: should_allow_custom_test is deprecated for the following: should allow_custom_test However all the documentation I can find is for the former macro setup by placing them in the shoulda_macros dir...

Paperclip error in rails3 on passenger

Rails3 on passenger. I have imagemagick installed and working correctly however I receive the following error when trying to add an image via paperclip. This works fine on in development, but not in production on passenger. [paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the...

Rails 3 - How do I remove database tables that have been created?

I created 2 models and ran the migrations, attempted some work on each of them and now I would like to start over and approach them differently. I'm new to Rails and have never attempted to delete/remove database tables (apart from rolling them back right after I migrated them). Thanks! ...

Rake db:seed - can I index Sphinx from there?

Is it a good idea to run rake thinking_sphinx:index from db/seeds.rb file? So that it will look like: #create some items #run rake thinking_sphinx:index Main intention behind that is to get fully functional environment after populating it with seed data. It is applied only to development env. ...

Refactor ruby helper method

I have a helper method which checks whether the collection of objects is empty? If not then it checks each one to make sure that the the existing event_id is not the @current_event.id. Here is my crack at it: def build_answers(question) if question.answers.empty? return question.answers.build else question.answers.each do |...