ruby-on-rails

Banner Management System using Rails

I want to create an open source banner/advertising management app using Rails. The app is like the simplified version of OpenX, where user can define the ad zone, upload banner, and paste the javascripts on the page to view the ads. This will be my first open source project and using this opportunity to learn Rails. But I searched aroun...

Mongrel: Can't resolve dns after cap deploy

I've got rails app I'm working on locally and uses geokit to talk to google and geocode addresses. I run the development environment using script/server (which runs mongrel_rails) on port :3000. Everything works just fine. Now, I've setup a staging environment and cap deploy that to a diff directory on localhost via ssh. The deploy work...

Name a reference in ActiveRecord

in my rails app, I have an Organization model, with a reference to a User, which I want to be able to access via organization_instance.adminstrator. I'm not sure how to accomplish this using the belongs_to method. ...

How can i visit urls with .html suffix

My rails version is 2.3.5(2.3+) How can I visit urls with .html suffix? Just like localhost:3000/welcome.html (welcome is a controller). I got routing errors when I visit urls above.But it works if the url with format param like this: localhost:3000/welcome?format=html In routes.rb: ActionController::Routing::Routes.draw do |map| ...

What is the convention when relevant data needs to be stored in a join table?

Suppose you have a data model that is something like class Question has_and_belongs_to_many :choices end Now suppose, on that choices model, there is a position column. What is the best way to access that information without having horrible messy queries / models? The beauty of has_and_belongs_to_many is that it keeps things concis...

ActiveRecord model with datetime stamp with timezone support attribute.

Rails is great that it will support timezone overall in the application with Time.zone. I need to be able to support the timezone a user selects for a record. The user will be able to select date, time, and timezone for the record and I would like all calculations to be done with respect to the user selected timezone. My question is wha...

Rails: Authlogic failed login URL?

On a vanilla Authlogic install set up a la Ryan Bate's Railscast #160, when a user goes to login and the session FAILS, the url changes from /login to /user_session (Of course, it shows the validation errors and all that jazz.) I want to keep the URL always at /login, even on failure (and still display the login errors). How woul...

Which is the best database strategy for a JRuby on Rails + legacy Java code?

We have a medium size Java application that needs some refactoring. We are considering migrating towards JRuby on Rails. Mainly because of the productivity that Ruby on Rails offers and for the many existing plugins that will reimplement the web logic. However a large part of the application should stay in Java, we do not want to rewri...

Ruby/Rails: Build internal service, no http support needed

I need to build an internal service that queues the DB for changes (in one table) every one second, and processed data after this event. I do not need all the Rails stack since this service does not need the Controller/View functionality. Basically, from the rails stack, i only need AR (or an ORM). The found solutions/approaches for t...

Rails: When testing controllers with RSpec, how do I stop them from redirecting?

I have controller methods that look like this: class TestController < ApplicationController def testAction render :json => { 'success'=>1 }.to_json end end When I load this action in the browser, I get what I expect: {"success":1} When testing with RSpec, however, response.body gives me '<html><body>You are being <a href="htt...

Rails link_to only hyperlinking part of link

I have <%=link_to distance_of_time_in_words_to_now(post.created_at), post %> ago However I want to make 'ago' show up in link as well. Now its something like '20 minutes ago,' which kind of looks ugly. I want it to look like 20 minutes ago.' I tried using #{} with no success and Google search turns out very little, especially since ...

How to handle one-off deployment tasks with capistrano?

I am currently trying to automate the deployment process of our rails app as much as possible, so that a clean build on the CI server can trigger an automated deployment on a test server. But I have run into a bit of a snag with the following scenario: I have added the friendly_id gem to the application. There's a migration that creates...

Correct this Rails/ruby method for me, please?

I've a post model with act-as-taggable-on gem. Both tables have timestamps. I started with def tags @posts = current_user.posts.find_tagged_with(params[:tag], :order => "@posts.tags.updated_at DESC"]) end And when that didn't work, I tried changing things and ended up with this mess. def tags @posts = current_user.posts.find_t...

How to insert a string into a textfile

I have a configuration file to which I want to add a string, that looks e.g. like that: line1 line2 line3 line4 The new string should not be appended but written somewhere into the middle of the file. Therefore I am looking for a specific position (or string) in the file and when it has been found, I insert my new string: file = File...

How to setup github.com like username url?

I've seen and googled and found many pretty url links. But they all seem to look like http://example.com/users/username I want it to be like github style http://example.com/username Any directions that I can follow?? ...

how to loop through a collection and find something in rails

I am new to rails and ruby. I have a has_many association between user and store below is what I do: @user = User.find_by_userid_and_password("someuser", "12345") => #<User id: 1, userid: "someuser", password: "12345", created_at: "2010-01-25 00:00:00", updated_at: "2010-01-25 00:00:00"> @user.stores => [#<Store id: 3, store_id: 3, ...

Rails complex form editing multiple records at once with associations

I am developing a complex form that updates several records of one model at once, whilst simultaneously updating an associated model. It looks a bit like this: class Sport has_one :photo end class Photo belongs_to :sport acts_as_fleximage end class Page # the page is not related to either of the previous models end Just for ...

Where to store temporary data in rails

In Ruby, I have a controller action that immediately initiates a computationally-intensive task that takes several seconds. I want the client to poll my server and get status updates. in my controller: def complex_task Thread.new do loop do one_part_of_the_computationally_intensive_task # Note how much progress we've ...

Access `session` within rails controller thread

How do I see / change session data from within a thread within rails? See this code snippet inside my controller: def controller_action session[:something] = 'before' # works properly Thread.new do session[:something] = 'after' # out of scope. <--- how do I fix this? end end (related to this question, but much more speci...

Rails, OpenID and Authlogic

I've been following ryan baytes screencast #170 and adding ruby-openid, authlogic and authlogic-oid to an existing authlogic authentication system. However, i keep getting the following stack of errors: NameError (uninitialized constant OpenIdAuthentication::InvalidOpenId): /Library/Ruby/Gems/1.8/gems/authlogic-oid-1.0.4/lib/authlo...