ruby-on-rails

Running into an issue with Rails 2.3.4 and Ruby 1.9.1: undefined method `^'

I am trying to test to see if a simple run of a rail application with a database will work and I am running in to an issue. Here are the steps I am taking: > mkdir MyApp > cd MyApp > rails myapp ... > rake db:create ... > ruby script/generate scaffold user first_name:string last_name:string active:boolean ... > rake db:migrate ...

Populating a database after "Sign Up"

I would like to populate various tables in my database after a new customer signs up to use our web application. I'm wondering what the best way to do this is, the main requirement being that it should not require any intervention by me. Most of the data is static (but can be changed by the customer later (like preferences for example)),...

apache2.2 x mongrel proxy error

I user apache2.2 mod_proxy_balancer + mongrel + rails2.3 Following error is occured. "proxy: Error reading from remote server returned by" I set this my httpd.conf SetEnv force-proxy-request-1.0 1 SetEnv proxy-nokeepalive 1 What's wrong? ...

Rails: Can joins be merged when chaining scopes?

In a class A I have two scopes, s1 and s2 which both join over a table T using the exact same join columns: named_scope :s1 :joins => "JOIN T on T.id = A.t_id", ...some conditions named_scope :s2 :joins => "JOIN T on T.id = A.t_id", ...some other conditions Now, doing this fails: A.s1.s2.all Error: ActiveRecord::StatementInvali...

Is it an issue to create a directory for each file upload, in a web application on linux/unix?

Hi, I am doing file-upload for a web-application (running on unix/linux). I'm wondering if there would be a concern if I planned to create a new directory for each file upload? This is the out-of-the-box approach for the Ruby on Rails plugin "paperclip". I debating what the trade-offs are, or whether perhaps it's just not a concern, ...

How to suspend execution of javascript?

Hi! Is there any way to suspend execution of javascript until whole page is loaded in a browser? I am updating a div at the bottom of the document using AJAX but when I click this link before whole page is loaded I get an error... <%= link_to_remote 'Update', :update => 'div_at_the_bottom', :url => { :usual_stuff } %> ...

Sharing templates with Rails and Javascript

So I have a have a solution for this, but I wanted to get some opinions and see if there was a better way to do this. My problem is basically that I list of data that will get generated on load by RoR and then have JS controls to view subsets. I would rather not have to support two versions of what is basically the same HMTL. So my sol...

Why find(:last) fail in my unit tests?

I have a one-to many relationship in Rails: class User < ActiveRecord::Base has_many :activities, :order => "added_at DESC" class Activity < ActiveRecord::Base belongs_to :user I have a method in Activity: def self.test_message(user, message) user.activities << Activity.create do |activity| activity.message = message ...

rails way to transfer polymorphic object through url

how do i pass a polymorphic object to another controller? for example redirecting from messages/1/ to requests/new?object_type=message&object_id=1 or, second example, from files/154/ to requests/new?object_type=file&object_id=154 is redirect_to new_request_path(:object_type => params[:controller].classify, :object_id => params[:id...

Does or can acts_as_tree be made to support eager loading?

Using acts_as_tree I would like to be able to preload an entire tree having its complete child hierarchy intact with one SQL call. To that end, I added a tree_id to the table and it runs through all descendants in that tree. I had explored acts_as_nested_set (actually awesome_nested_set) as a possibility but since I graft trees into ot...

jQuery + Rails + ajaxForm + js.erb problem

I'm having an issue that is driving me nuts, and according to everything i have seen and read online, it should be working fine. I'm using jQuery with my Rails app instead of prototype and am using the ajaxForm plugin to submit some form data via ajax. The form data gets submitted fine, the corresponding controller action gets called f...

Catch initialization error in Ruby on Rails

What I want to do: redirect the user to a special error page if the database is down. I'm using an Oracle database with the OCI adapter. It appears that, if the database is unavailable (say, down for backup), that the OCI adapter throws an error before I ever hit a controller (based on the stack trace, it's while it's setting up the co...

Rails Exception Notification Plugin - Force send email

I'm using the Rails exception_notification plugin in my app and find it very useful. However, there are occasions when I want to catch an exception and deal with it gracefully but still would like to receive the exception notification email. It only seems to send for uncaught exceptions it seems. Does anyone know how to force send the ...

Rails db:create collation error

I'm having an issue when running rake db:create: [root@zephyrnode /domain/rails/testapp ]# rake db:create --trace (in /domain/rails/testapp) ** Invoke db:create (first_time) ** Invoke db:load_config (first_time) ** Invoke rails_env (first_time) ** Execute rails_env ** Execute db:load_config ** Execute db:create Couldn't create database ...

Anyone can suggest a jquery lightbox plugin that allow embedded html and is easy to custom CSS?

there are the criteria can style the modal box(round corner, window and background color etc ) allow embedded html and custom its position can custom style for the 'forward' and 'back' buttons, their images and positions have a 'play' button for image slideshow or allow custom JavaScript to do so thanks ...

Setting up polymorphic associations in db when the super is a FK of subclasses?

Using class table inheritance it is recommended that the subclass refers to the superclass and not the other way around. Normally in Rails polymorphic associations work in the other direction--the super refers to the subclass. Recommended vehicle .id car .vehicle_id # PK instead of using id (identity column) boat .vehicle_id...

Facebook FBML requests do not send mime type?

I would like to respond to different formats in my Rails app: respond_to do |format| logger.info "in main format block, request.format.fbml? = #{request.format.fbml?}" format.html # index.html.erb format.fbml # index.fbml.erb end This is simple. If facebook is requesting a page, return a .fbml.erb file, otherwise return a .h...

How to assert action returns correct text?

Is there a standard or best-practices way to test that an action in rails is returning the correct text? For example, I have a simple action that is used for doing ajax validation that does the following: def get_object_id if params[:id].blank? return render(:text => -1, :layout => false) end my_object = MyObject.find_by_id(...

BBCode for Ruby on Rails

So I'm putting together a simple forum. I'd like to allow my users limited formatting options and BBCode would be plenty for my users. Knowing that I'm assuredly not the first one to want to use BBCode with RoR I googled but couldn't find a straight forward tutorial on how to create a editor which accepts BBCode nor a way to parse and di...

Validating model relationships in rails

What's the right kind of validation to include for subordinate models? For example, let's say you've got books with chapters. The number of chapters per book is determined when the book is first created. class Book < ActiveRecord::Base has_many :chapters def build_chapters(count) (1..count).each do |i| chapters.build(:s...