ruby-on-rails

Rails: Submit javascript variables along with form

I'm using the Google Maps Javascript API so that I can have someone put a marker on a map and then get the latitude and longitude from that to submit as part of a form. I know how to get the data from the Maps api just fine, but I can't figure out how to submit the javascript variables that I have to the rails form? An event is called e...

How do I use rails route helpers with jQuery?

I would like to use the jQuery ajax method $.get to access a restful route in rails. Something like this (keep in mind this is done in a haml template where I can use string interpolation): $(function(){ $(':radio').change(function(){ $.get("#{edit_steps_path(N)}"); } }); In the snippet above #{steps_path(N)} interpolates to...

create.js.erb, destroy.js.erb: How do these files fit in a Rails app

I haven't been able to find documentation that talk about how create.js.erb and destroy.js.erb fit in a Rails 3 app. What is the logic behind these types of Javascript files in the app > controllers? How and when are they accessed? ...

Ruby on Rails 3: link_to create new nested resource?

I am trying to make a link to create a new nested resource in my Rails 3 application, but I can't figure it out. What is the syntax to link to a new nested resource Solution: Make sure you have your resources properly nested in your routes file. resources :books do resources :chapters end Then in your view script you can call it l...

How do you convert an ISO 8601 date to a UNIX timestamp in Ruby?

I've been trying Time.parse() and Date.parse(), but can't see to figure it out. I need to convert a date in the form "2007-12-31 23:59:59" to a UNIX timestamp. Something like PHP's strtotime() function would be perfect. ...

Ruby Rack issue

I am newbie to Ruby on Rails This is what happened I got a hosting from bluehost which supports RoR. I download a Rack-based open-source web font server. I copied that to my hosting domain. I tried to startup that server using rackup filename.ru, but rackup is not avaliable... what 2 do now How to start this server. ...

What are the authentication options available with Rails 3 ?

My current project is in rails 2.3.5 which uses restful authentication. I am moving this app to rails 3.. I want to know about the compatibility of authentication plugins with rails 3. Can i use authlogic with rails 3 ? Is it reliable ? what other options do I have for a very simple user authentication to work with rails 3 ? thanks ...

Convert Byte Array into HTML Image with Rails?

I have a Byte Array field being returned to me by the database, and in the view, I need to somehow output that as an image. How would I do that in Rails? Many thanks, M ...

How to write unit tests for STI associations Ruby on Rails

What steps should you use when in a need to write unit tests for STI associations. I am completely confused. Please provide some suggestions or links to some tutorials. Thanks in advance ...

GIT / RubyMine (Leopard) - can't pull but I can commit and push

Hello, Ive got weird problem My system is Snow Leopard (10.6.4) - I can't make pull from my RubyMine but I can make commit and push. The best thing is that when I run terminal and type "git pull" it works fine. In ruby mine console there are some errors: /usr/local/git/libexec/git-core/git-sh-setup: line 71: basename: command not foun...

Multiple database support

Hi, Did you get any way to have different database session for different user session?? If yes please tell me how to do that. Thanks Nitin ...

Radio button and having a text box validation ruby on rail

Hi, This is currently the setup I have: <input id="demographics_questionary_gender_male" name="demographics_questionary[gender]" type="radio" value="Male"> Male <input id="demographics_questionary_gender_gender" name="demographics_questionary[gender]" type="radio" value="Female"> Female <input id="demographics_questionary_gender_male" ...

Apply validation to single object only - Rails 3

Lets say I've Comment class that is polymorphic and I use it in many places within a system. class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true attr_accessible :content end And there is this one place in which I would like to apply validation on Comment's content length. How should I approach this prob...

How can I compute a conditional sum in my model?

Say I want something like this in Rails: class Proposal < ActiveRecord::Base def interest_level self.yes_votes.count - self.no_votes.count end private def yes_votes self.votes.where(:vote => true) end def no_votes self.votes.where(:vote => false) end end What have I basically done w...

Best way to handle multitenancy in Rails 3

Hi guys, I'm building multi-tenant application. All data isolation is done by TenantID column in each table. What is the best way to automatically handle multi-tenancy for all tenant models. Example: Contacts.new({.....}) should automatically add :tenant => curret_user.tenant Contacts.where({....}) should also add :tenant => curret_...

Integrate Mongoid and CanCan

Hi guys, Have somebody tried to rewrite CanCan ActiverRecordAddtions for Mongoid http://github.com/ryanb/cancan/blob/master/lib/cancan/active_record_additions.rb Regards, Alexey Zakharov ...

RoR-jquery jCarousel error

hi i am using jquery.jcarousel.js, and iam coming across the error- jCarousel: No width/height set for items. This will cause an infinite loop. Aborting... please guide me how i can fix it ...

cache-money requires Ruby version >= 1.8.7. any wayout to work with 1.8.6

I am having performance issue in my application I want to use memcache I am using ruby version 1.8.6. Can anyone suggest me best way out. I want something similar to cache-money or any wayout using 1.8.6 I can use cache-money ...

Rails - field_error_proc and custom form fields.

In rails forms built with form_for, all of the fields called on the form object f are wrapped in an error div if they have caused a validation failure and the form page is re-rendered. However, if i have a form that has hand-built fields, instead of fields called on the form object f, they don't get this. Is there a way that i can trig...

after_add callback for has_one

This seems to be an inconsistency between has_many and has_one. The has_many association allows you to specify an after_add callback that is called after an object has been added to the collection. class Person has_many :parents, :after_add => { puts "Added new parent" } # allowed has_one :car, :after_add => { puts "Added car" } #...