ruby-on-rails

Solr/Lucene is it possible to order first by relevance, and then by a second attribute?

In Solr/Lucene is it possible to order first by relevance, and then by a second attribute? As far as I can tell if I set an ordering parameter, it totally overrides relevance, and sorts by the ordering parameter(s). How can I have results sorted first by relevance, and then in the case of two entries with exactly the same relevance, gi...

Migrating Rails restful authentication users to Django

Hello! I'm looking to migrate users of a rails app which uses the Restful Authentication module (which uses a stretched sha1 encryption algorithm) to a Django app, using the default authentication framework (which uses a plain sha1 algorithm). Does anybody know how I can make this happen? specifically, can I somehow implement the same e...

When and when not to stub/mock a test

I am making a concerted effort to wrap my head around Rspec in order to move towards more of a TDD/BDD development pattern. However, I'm a long way off and struggling with some of the fundamentals: Like, when exactly should I be using mocks/stubs and when shouldn't I? Take for example this scenario: I have a Site model that has_many :b...

ActionController::InvalidAuthenticityToken in SessionsController#create error

Hi, I get this error in Rails 2.3.9 but not in 2.3.8. I didn't changed any code. Did I missed anything? ActionController::InvalidAuthenticityToken in SessionsController#create ActionController::InvalidAuthenticityToken Thanks :) Here are the added details. Request Parameters: {"commit"=>"Login", "authenticity_token"=>"A9A4+sCsA/...

Rails: Set cookie only on www subdomain?

I have set up an asset host at assets.domain.com but it appears that cookies are being sent with requests to assets.domain.com. I read somewhere that if you have cookies set to domain.com then this will happen. So I guess I'm trying to set cookies only to www.domain.com so that requests to assets.domain.com will not send cookies. (I als...

Authlogic Perishable Token Resetting on Failed Login

I am using the perishable token magic in authlogic to do password resets. However, it seems that the token is getting reset when a user tries to log in and fails. This is because authlogic is incrementing failed login attempts on the user record. So if the user requests a new password and then tries to log in before resetting the pass...

A tool to automatically generate a UML diagram for a Rails Application

Looking for a good tool/gem that can automatically generate a nice looking UML diagram for an existing rails application. (Im imagining such a tool would read the schema.rb file and then scan the models for relationships) ...

What is this line of Rails code doing?

def role?(role) return !!self.roles.find_by_name(role.to_s.camelize) end Can you help me understand what's happening in the code above? I'm new to Rails/Ruby. Thanks ...

Ruby/Ruby on Rails vs PHP

We do not get much projects in Ruby, we are so far focused only on PHP. As a web development agency are we missing an important channel of revenue due to our unopened nature with Ruby and Ruby on Rails? If we start doing some local projects, learn Ruby, is is possible to open another revenue channel? Is it wise to ask PHP developers to l...

Rails saving datetime to MySQL database

I have a simple function within my model to set a completed datetime column in a database. this function worked until I tried to change the default rails format for datetime. After reading up on the issues with mysql datetime format and rails I decided to take out the formating code I had in the environment.rb It still does not save t...

Special character in database.yml for password.

Hi All, I have my database password starting with a '*'. When i put this on my production server i get following error: - syntax error on line 17, col 25: ` password: *---------'.Exception class:ArgumentError. Thanks, Anubhaw ...

what could cause an "IOError(closed stream)" in jruby?

i've spent the last three days trying to get a jruby/rails/couchdb app deployed to a linux/tomcat environment. i'm ready to shoot something. my current issue is this - there is a specific gem, "simply_stored", that acts at the top level driver for couchdb. whenever i hit code in the app that touches this gem, i get this ruby trace: IOEr...

Rails: paginating by method, not by column

Is there a way in Rails (using will_paginate or any other kind of pagination) to paginate by a method? For example, I have a Movie table, associated with user ratings. I want to be able to paginate the movies based on the mean or standard deviation of the ratings (which are defined in methods in the Movie class, not as part of the datab...

How to get a before filter in Mailer?

Hi, Am using action mailer in ruby on rails. I just want to filter the recipient emails according to email_bounce flag in users table. Is it possible to use any filter in mailer ...

In Ruby on Rails, how can a model "has_many" and "belong_to" using a different field other than primary ID?

I am trying building a simple project from scratch using Rails 3. Usually, the models are like: class Student < ActiveRecord::Base has_many :awards end class Award < ActiveRecord::Base belongs_to :student end and we use the award.id and student.id to get the corresponding records. But what if it is class Company < ActiveRecord...

How do I get nginx and phusion passenger to maintain sessions between 2 rails instances?

I'm using nginx with phusion passenger to run a rails app on an ec2 CentOS machine. I have a pretty standard set up with nginx, rails, phusion passenger and ssl (I think). My nginx.conf is below. So far it has worked out fine except that every time 2 requests hit the server at the same time, a new rails instance is created to serve the ...

How to use the Rails 2.3 app generator when I have Rails 3 installed?

Hi, to clarify: there's only one rails command, which gets installed from the latest Rails gem, which is Rails 3 ATM. However, I'm required to create a Rails 2.3 app. Running ruby /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails fails with a NoMethodError, I suppose because it also tries to use gems from the 3.0.0 release. Unin...

passing values into as_json via options hash?

I'm trying to pass an object (the current user) to be used when rendering the json for a collection. respond_to do |format| format.html # index.html.erb format.xml { render :xml => @items } format.json { render :json => @items.to_a.as_json(:user => current_user) } end However, this seems to have no effect as options[:user] is ...

Rails 2 to Rails 3, method verification in controllers gone?

Coming from rails 2, most of my controllers would have these lines: verify :method => :post, :only => :create, :render => {:text => '405 HTTP POST required', :status => 405}, :add_headers => {'Allow' => 'POST'} verify :method => :put, :only => :update, :render => {:text => '405 HTTP PUT required', :status => 405}, :add_headers => {'Allo...

Loging Active Record save method call in Rails 3 - how

Hi, I'm looking the best way to log some of save method call. It will be save in another database. I need to log model and its attributes, and user model, which should be somehow taken from session. How to make it Rails Way? ...