ruby-on-rails

Rails I8n: Use default locale when the requested locale (from HTTP header) is not available?

Hi: In my Rails ApplicationController I have added the following methods (from rails guide docs) to support I8n based on http accept language header info. Is there a way to check if the requested locale is available and if not, use the 'english' default locale as marked in environment.rb? Otherwise I get "translation missing" when an unk...

Howto change view format based on domain name

Hi all, I wanted to know if there are any way to change the view format for based on domain name the same rails app. For example : www.domain.com => respond_to format.html api.domain.com => respond_to format.xml or format.json Thanks all for your help ...

How to omit existing child records in a nested form in rails?

In my application an User has many Projects. I want to create a "add many projects" form, so the User can create many Projects at once. It seemed to me that the quickest way was to make a User form with Project fields nested in it, and omit the User fields. This way when the form is submitted, the User is saved and all the new Project r...

Rails: Change default format of the date_select helper?

How can I change the default order of the date_select helper? ...

Installing Ruby choices

I need to setup my laptop for ruby development. At the moment I use MAMP Pro for my PHP apps, but now I'm branching out into Rails development I feel that I should get setup correctly. Are there any advantages to using SQLite rather than MySQL for local developing and then deploying it to a MySQL database? Am I on the right track? Any ...

Rails Functional Test using Recaptcha

My UsersControllerTest currently fails because I use verify_recaptcha in UsersController#create. How can I write my tests such that a known good CAPTCHA response is passed with params[:user]? I am using reCAPTCHA, but I suppose the question would apply to any CAPTCHA implementation. Here is my UsersController#create def create @user ...

Page-view-counter with Rails and Memcached

Hi! I'm trying to implement a page-views-counter with Rails and memcached. Every time I render a page, through rails I increase a memcached key (key.incr is atomic). My main worry is the possibility where this key gets expired or deleted from memcached before I update my DB record. Even if I visit all the keys with frequency greater tha...

How do I override the RJS MIME Type in Rails 2.3?

I have an app running Rails 2.3.5 that has a JSON API for much of it. A contractor came in and did some work on the app and used RJS in a few places. Some of those controller actions that are using RJS for the main web site also need to be part of the API. The problem is that JSON API requests trigger the RJS responses, which is not w...

Rails page caching and flash messages

I'm pretty sure I can page cache the vast majority of my site but the one thing preventing me from doing so is that my flash messages will not show, or they'll show at the wrong time. One thing I'm considering is writing the flash message to a cookie, reading it and displaying it via javascript and clearing the cookie once the message h...

Using an existing database of another Rails application in a new Rails application

I'm new to Rails. I had created a Rails application earlier and also collected a few data records in the development database. Suppose, I create a new Rails application and I prefer to use the existing development database of the 1st Rails application in my newly created Rails application, how do I do that? ...

Is it possible to debug unit tests in Ruby on Rails?

So, I just moved to new project that is built on Ruby on Rails. I'm new to it and I'm still learning it. I can debug most of the application code, but it seems I can not debug unit test code and code that is tested. When I run unit testing in debug mode, I can set a breakpoint in unit test class code, for example where fixtures are adde...

Ruby on Rails with Plupload

I am looking for an upload solution for Ruby on Rails where I can upload multiple large image files simultaneously and show the progress to the uploader so they know the files are being uploaded. I stumbled onto Plupload which seems perfect for what I'm trying to do, but I can't find any Ruby on Rails examples on how to incorporate into ...

has_many :through association through two different associations

I have four model classes: class Group < ActiveRecord::Base has_many :projects has_many :personal_blogs end class Project < ActiveRecord::Base has_many :events, :as => :event_producer end class PersonalBlog < ActiveRecord::Base has_many :events, :as => :event_producer end class Event < ActiveRecord::Base belongs_to :event_p...

Rails gallery app hosting

I'm building a rails gallery app for a company that doesn't want to host it themselves. They estimate that it could potentially get 1000 or so unique visits a day. What I'm pondering is... should the images be on a static file server such as S3 or rackspace cloudfile, or should they just be left on the same server as the app? There is pl...

Strange issue using HAML

When I copied _form.haml partial to _edit_form.haml partial and replaced "_form", with "_edit_form" in my edit.haml I got strange error (maybe it is not strange, I just cant understand the reason). wrong number of arguments (0 for 1) Extracted source (around line #1): 1: = form.label :email 2: %br 3: = form.text_field :email 4: %br ....

How to add parameters to a ruby on rails post?

Hi, Say I have a model called User that has the following parameters: favorite_color, favorite_animal, and lucky_number. The user fills in the form containing only favorite_color and favorite_animal. When the form is submitted, I want to run a function that takes the color and animal into account and comes up with a lucky_number. How do...

Bizarre Ruby on Rails Error (AssociationTypeMismatch)

hi Guys - Real problem with an existing webapp which has been working for the last couple of years... ActiveRecord::AssociationTypeMismatch (Note(#23706868500220) expected, got String(#23706844996600)): app/controllers/jobs_controller.rb:56:in `new' app/controllers/jobs_controller.rb:56:in `create' Line 56 of jobs_controller.rb: ...

Capture HTML output from the view in RAILS and save to DB

Is there a way to capture the output of my view file after it is rendered? I basically want to save the full HTML output into a database after the page renders. ...

How to install gems from RubyForge?

I am trying to install ruby-mp3info as a gem on my computer. Running sudo gem install ruby-mp3info seems to work OK. In my environment.rb file, I added config.gem "ruby-mp3info". When I try to run the server, it fails, claiming I have some missing gems Following the error message's advice: Run `rake gems:install` to install the missing ...

How to make iframe pop-up in dialog?

<%= button_to_function("Complete an Offer", "ABA.dialogs.offer(#{???}, {title: 'Complete an Offer'});", :title => "Complete an Offer") %> When a user clicks the button, I want an iframe* to pop-up in a separate dialog box. Any pointers? * ...