ruby-on-rails

How do I setup a rails project to use an edge source tree (not an installed gem) version of rails.

I would like the rails 3.0 source tree in my project so I can use patches, etc. I don' want to freeze rails. I would like to be able to pull updates from the main repo too. How do I accomplish this? In particular the getting started guide, has me confused with As the root user: # gem install bundler # bundle install If I install the ...

Gem or Plugin , what is good for a ruby on rails project

I am facing some problem with rails gem when deploying to a differet machine.It requires some extra work on installing gem.Which is most suitable for a rails project.Plugin or Gem. For Some gems there is no corresponding plugins found. I am searching for advantages of using plugin over gems and vice versa. ...

How to convert a gem to plugin in ruby on rails and vice versa?

Is there any tool to convert plugin to gem and vice versa. ...

Polymorphic Join Table in Rails?

In my app, an Event has multiple items associated with it, potentially all of different types. For example, a "User ate a Banana" Event would have a User and a Banana associated with it. It seems like one way to accomplish this would be to have a polymorphic join table with 3 fields: event_id, attachable_type, and attachable_id, where ...

Rails.cache.fetch, Symbols, & Memcached

I have a rails 2.3.4 app and a line that looks like: temp = Rails.cache.fetch(:temp_id) { User.find_by_name('Temp').id } and everything worked fine, until I decided to switch the caching layer to memcached by adding the following to my environment.rb: config.cache_store = :mem_cache_store Now the line which used to work fine gives...

How to judge whether a time/date is today, in ruby?

I have a settlement,I want to judge if the return_service_date is today,how to do this? This is my code (rails) if settlement.return_service_date && settlement.return_service_date.to_s(:date) == Time.now.to_s(:date) Is there a better way to do this? ...

Autocomplete Ajax - Get Complete list of Cities by State?

I just tried creating an Event on EventBrite and they have this nice autocomplete input for cities (start typing "san" and it will bring up "San Francisco, California..." and a list of others). What's the best way to do that? Do you need to store that in a local database or do people make those ajax calls to something like google maps ...

HashWithIndifferentAccess when saving array of objects

Ok so I have these 2 classes class Interface < ActiveRecord::Base belongs_to :hardware end and class Hardware < ActiveRecord::Base has_many :interfaces end I have a form for a predefined @hardware.interfaces which includes array of Interfaces which is handled like below <%= text_field_tag "hardware[interfaces][][name]",i...

delete inner a transaction?

My test Code UserAccount.transaction do MyModel.delete(1) a = 1/ 0 end I find the delete will not rollback. how to fix this problem? is there anyway to disable the transaction in delete method? ...

Any Java implementation of RoR's distance_of_time_in_words and time_ago_in_words?

Do you know if it exists a java implementation of distance_of_time_in_words and time_ago_in_words? For those who don't know, these methods return a human readable description of the time interval between two dates or between a date and now. By example: 3 days A week ago 2 minutes ago More than a year ago ...

How to add a new action in Ruby on Rails ?

Hello! I have this in routes.rb map.namespace :admin do |admin| admin.resources :projects, :has_many => :products end What I would like to is to be able to set the something in the routes.rb file in order for me to use new action in the products controller. Actions added by hand after scaffolding. I tried something like this m...

How can i include image into CSV

Hi In my Rails application Admin can export the user data into csv format. Every user in my application has their profile photo.... my client wants to include the user photo into the CSV file .. I have not how to do this . can any one please help me.... i am using fastercsv gem and here is some my controller code for reference In m...

Rails ActiveRecord conditions

Is there a way to create a condition like this? @products = Product.find(:all, :limit => 5, :conditions => { :products => { :locale => 'en', :id NOT '1' }, :tags => { :name => ['a','b']}) I would like to list all products not including product 1. Thx. ...

How to ignore duplicate inserts with datamapper

I have a datamapper model that has a unique index on a property called name. I want to create new records when a name doesn't already exist and silently ignore attempts to create records with duplicate names. What's the "right" way to do this in datamapper? ...

My Rails app is returning HTTP 500 for all its URLs, but nothing shows up in the log file. How can I diagnose the problem?

I have a Rails app that is running on a production server with Apache and Phusion Passenger. The app works fine locally when using Mongrel, but whenever I try to load a URL on the production server, it returns HTTP 500. I know the server is working properly, because I can get the static elements of the application (e.g., JavaScript files...

How to test custom helper in Rails?

How can I test a helper method living in app/helpers/application_helper.rb? I have this code in my file test/unit/helpers/application_helper_test.rb require 'test_helper' class ApplicationHelperTest < ActionView::TestCase test "category" do assert categories_collection end end But I get this error "NameError: undefined lo...

As of 2010, what good Rails-based content management systems are there (Typo?)?

I Googled this question and came up with answers (and CMSes) from pre-2009, so I was wondering if the state of RoR CMSes had changed much since then? I don't need a full-fledged CMS...I have a custom app in mind that I would like to attach blog/article/editor tools functionality to, without having to re-write those parts myself. So any ...

build_* not working despite being has_one

Hey all, My intention here is just to create a corresponding contact when a user signs up, but the said contact is never created, despite using build_* with a has_one: Contact model: has_one :user User model: belongs_to :contact Users Controller: def signup @user = User.new end def signup_success @user = User.find params[:id...

Strange variable-argument problem in Capistrano Task

Hello stackoverflow experts, I got a very strange problem in a task I'm creating with Capistrano. I'm trying to pass a variable from the command line: >> cap create_dir -s name_of_dir=mydir task :create_dir do printf("#{name_of_dir}") if !(exists?(:name_of_dir)) then name_of_dir = Capistrano::CLI.ui.ask("Name of dir to be ...

Rails Sanitize: Safety + Allowing Embeds

We're building a user generated content site where we want to allow users to be able to embed things like videos, slideshares, etc... Can anyone recommend a generally accepted list of tags / attributes to allow in rails sanitize that will give us pretty good security, while still allowing a good amount of the embedable content / html for...