ruby-on-rails

Rails3: ActiveRecord model relationship with YAML file

Hi, I have an ActiveRecord model Group and a YAML table stored in config/users.yaml just like: - {login: titi, password: 123456, group_id: 2} - {login: toto, password: 987654, group_id: 7} And I would like to link them by a sexy way. Can you help me? I would be happy if I can do this (as example): User.first.group.id # => 2 M...

Why am I getting "ArgumentError: wrong number of arguments (1 for 0)" when running my rails functional tests?

I'm stumped on what's causing this. I get this error and stack trace in all my functional tests where I call 'post'. Here is the full stack trace: 7) Error: test_should_validate(UsersControllerTest): ArgumentError: wrong number of arguments (1 for 0) /Users/hisham/src/rails/ftuBackend/vendor/rails/actionpack/lib/action_controller/...

How to integrate Facebook the new Graph Api with Authlogic in Ruby on Rails?

I've began with a new project using Authlogic system for Authorization. And I'm now wondering how could I connect Facebook oAuth sessions with my Authlogic session! First of all I want to use and Authlogic-oAuth Gems/Plugins, I what I want to use are just http://github.com/intridea/oauth2 and the interesting http://github.com/nsanta/...

What is the reason to use observe_field instead of onkeydown in rails?

Is there any good reason why most rails developers use observe_field when they want trigger specific action when text input box is changed, rather then using onkeydown? I would expect, that in most of the cases using observe_field results much more code generated than just using native hook onkeydown. ...

has_many through and saving to join table

I have the following: class Invite < ActiveRecord::Base belongs_to :user has_many :invite_recipients has_many :recipients, :through => :invite_recipients end class InviteRecipient < ActiveRecord::Base belongs_to :invite belongs_to :user_comm validates_associated :user_comm, :invite validates_uniqueness_of :user_comm_id, ...

Observer not clearing cache in Rails 2.3.2 - please help.

Hi, We are using Rails 2.3.2, Ruby 1.8 & memcache. In my Posts controller I have: cache_sweeper Company::Caching::Sweepers::PostSweeper, :only => [:save_post] I have created the following module: module Company module Caching module Sweepers class PostSweeper < ActionController::Caching::Sweeper observe Post ...

Rails - Preventing users from contributing to website when their score is too low - callback / observer best practice etc

A User can add a Sentence directly on my website, via Twitter or email. To add a sentence they must have a minimum score. If they don't have the minimum score they can't post the sentence and a warning message is either flashed on the website, sent back to them via Twitter or email. So I'm wondering how best to code this check. Im thin...

jQuery ajax, firefox with 302 redirects?

I'm having problems in Firefox with 302 redirects coming from my Rails app. Right now I have $.ajax({ url: '/model/33', type: 'POST', data: 'authenticity_token=efjowiejfoiwej&_method=put&model[value]=aaa', complete: myFunc }); function myFunc() { //do what I want } This works fine in other browsers, but in Firefo...

Combining Two Models in Rails for a Form

I'm very new with rails and I've been building a CMS application backend. All is going well, but I would like to know if this is possible? Basically I have two models: @page { id, name, number } @extended_page { id, page_id, description, image } The idea is that there are bunch of pages but NOT ALL pages have extended_content. In t...

Technology stack for very frequent gps data collection

I am working on a project that involves gps data collection from many users (say 1000) every second (while they move). I am planning on using a dedicated database instance on EC2 with the mysql persistent block storage and run a ruby on rails application with nginx frontend. I haven't worked on such data collection application before. A...

Execute script with Ruby on Rails?

I want to start my daemon with my application. In the command line, I can write something like lib/daemons/mydaemon_ctl start to start up my daemon, but I have to do this manually. I want the daemon to start when I start my server (i.e. when the initializer files are loaded). Is there a ruby command for executing a command line? Someth...

Pushing app to heroku problem

I am trying to push my app to heroku and I get the following message: $ heroku create Creating electric-meadow-15..... done Created http://electric-meadow-15.heroku.com/ | [email protected]:electric-meadow-1 5.git $ git push heroku master ! No such app as fierce-fog-63 fatal: The remote end hung up unexpectedly It's weird that I am...

Stop daemon with server in Ruby on Rails

I have a daemon that I'm starting along with the server using an initializer file. I want to stop this daemon once the server stops, but I'm not sure where to put a script that would run when the server stops. Initializers get automatically loaded when the server starts. Is there a similar "destroyers" folder? Where would I put code tha...

Multiple Rails forks with separate designs and layouts

I have a Rails project that is basically a simple web app for a membership-based organization. We've open sourced the code on Github for the web app so that others can use it, but have a licensed design/layout that the original organization is going to use. This layout cannot be open sourced. I was wondering if others have run into the s...

Rails: Getting rid of generic "X is invalid" validation errors

I have a sign-up form that has nested associations/attributes whatever you want to call them. My Hierarchy is this: class User < ActiveRecord::Base acts_as_authentic belongs_to :user_role, :polymorphic => true end class Customer < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attrib...

One Account with many users authentication in rails

Which approach would you recommend to the following issue: My app needs to have an account with several users inputting tasks on the same account. Only one of the users (the one that opened the account) will have admin privileges. I'm thinking on using Authlogic for authentication and CanCan for determining user privileges. The point is...

Is there a difference between plain text emails, and multipart emails with only plain text?

I'm using Rails to send emails and I just want to send a plain text email (there is no corresponding HTML part). I've noticed that if I just have one file named email.text.plain.erb it actually generates a multipart email with one part (the plain text part) like this: Content-Type: multipart/alternative; boundary=mimepart_4c04a2d34c4bb...

regular expression for emails NOT ending with replace script

I'm currently modifying my regex for this: http://stackoverflow.com/questions/2782031/extracting-email-addresses-in-an-html-block-in-ruby-rails basically, im making another obfuscator that uses ROT13 by parsing a block of text for all links that contain a mailto referrer(using hpricot). One use case this doesn't catch is that if the us...

Authlogic::ControllerAdapters::RailsAdapter::AuthlogicLoadedTooLateError

Authlogic is trying to prepend a before_filter in ActionController::Base to active itself, the problem is that ApplicationController has already been loaded meaning the before_filter won't get copied into your application. Generally this is due to another gem or plugin requiring your ApplicationController prematurely, such as the resourc...

Access attributes/methods comments programmatically in Ruby

Is there a way for programmatically accessing a method comments? or an attribute comments? I would like to use it as a description for the method in a documentation which I don't want to be static or generated with rdoc or equivalent. Here is an example of a Ruby class: Class MyClass ## # This method tries over and over until it i...