ruby-on-rails

How do I filter or find a Model based on a method in that Model?

Hi, I have a controller which is looking for a set of Contacts from the Contacts table. Currently it looks like this: @contacts = @campaign.contacts.find(:all, :order => "date_entered ASC") The method in the contact.rb (Model) is this: def status return if statuses.empty? a= statuses.find(:last).status << ' (' << statuses.fin...

How can I tell if a user has left my website

Is there a way to tell if a user on my website has left (i.e. connection dropped, navigated away etc.) in real time? I am building a RoR website and want to initiate an event as soon as a user leaves my site for whatever reason (e.g. connection, navigating away from domain etc.) Thanks in advance for any help. ...

Using brackets in cookie names (Rails)

When attempting to write/read cookies that have brackets in the name, it seems like Rails can't handle this. For example: cookies["example[]"] = "value" This causes the cookie name to be "example%5B%5D" instead of "example[]". Similarly, if I already have a cookie set with the name "example[]", then it seems like Rails is unable to ...

Redmine - Ruby - Looking for the value of a custom field.

I checked IRC for redmine and was unable to get help. I was conflicted on weather to stick this on Superuser, ServerFault or here, but as my problem is technically programming oriented I decided to look for help here. We have a Mercurial repository system with a layout based on projects that addresses our needs. I wrote some shell scrip...

Convert a Ruby on Rails project to a JRuby on Rails project

Hi, is there any particular way to convert a Ruby on Rails project to a JRuby on Rails project? There now is a need to get the Rails side to talk to a Java server via RMI so was wondering how to make the conversion. Thanks. ...

Ruby on Rails: How do I specify which method a form_tag points to?

I have this: <% form_tag :controller => :proposals, :method => :bulk_action do %> but it errors in the create method... which is weird because I'm trying to tell stuff to delete. ...

Stale record in multiprocess environment

I have a database that is shared among possible different Ruby on Rails processes. To keep consistency, I would like the record I operate on is up-to-date. I am hoping to solve this problem: process A reads a record, process B reads the same record, process A update the record, (now the instance of record in process B is stale). Since t...

Type method interfering with database type column problem

I'm using Ruby on Rails and the paths_of_glory gem I need to access the types of achievements that a user accomplishes in order to display a picture along with each particular achievement. When I try to access it via @user.achievements.type, I get an error that says that it wants to return "array" (as in achievements is an array) inste...

How to change the directory public assets are served from in rails?

My setup: thin running on port 1234 with --prefix /foobar apache running on port 80 apache reverse proxies /foobar to thin on port 1234 I would like the static assets to not be served via the proxy to thin, but instead be served at /assets directly via apache instead. I have to use a relative path because I don't know the host name/...

How can I use uncountable nouns in resource routes with Rails 3?

I have a model called Aircraft, inflected as uncountable, and it's driving me nuts. What is the correct way to handle this in Rails 3 "beta 4"? resources :aircraft do member do get :flights end end # Of course these work for some actions and not others. match 'aircraft', :to => 'aircraft#index', :as => :aircraft match 'aircraft...

Should I use has_one or belongs_to in ruby on rails?

I want to have a model called Status which will be relatively static after some user-defined set up (and different users may have different values on status). The status can apply to different Models, such as Contact and Events. so contact.status set of possible values will be different from event.status I want to design the app so th...

Help refactoring named_scope...

I have the following named_scope: named_scope :commentors, lambda { |*args| { :select => 'users.*, count(*) as total_comments', :joins => :comments, :conditions => { :comments => { :public_comment => 1, :aasm_state => 'posted', :chalkboard_user_id => nil} }, :group => 'users.id', :having => ['coun...

What is middleware when referenced in the context of Ruby on Rails?

I often hear the term 'middleware' in the context of Ruby on Rails. What exactly is it? Can you provide specific examples? ...

Filtering results based on a many-to-many relationship

Posts belong to Users. Users have and belong to many roles (i.e., the tables we're dealing with here are posts, users, roles, and roles_users) How can I select all posts written by a user who has the "Editor" role? I.e., I want the database-driven version of Post.all.select{|p| p.user.roles.map(&:name).include?("Editor")}} ...

Reproduce Evernote web clipper in a Rails app.

I would like to write a Rails app that is able to capture a webpage like the Evernote clipper does. If you are not familiar, in your browser, you can click a button on the toolbar and it captures a pretty accurate copy of the webpage layout. For an example, go to http://www.evernote.com/pub/jssmith072/shared and click on the single note ...

How to do something on user's first visit without checking subsequent visits in Rails

Suppose you want to show a message to a user who has logged in for the first time like, "Thanks for signing up". Of course this is easy to achieve, but it seems a waste to check if it is their first visit (by any mechanism) every time thereafter. Is it possible to do it in any way that doesn't involve checking every time? I suppose th...

Rails has_many nested field

Hello, i have these two models: class Artist < ActiveRecord::Base has_and_belongs_to_many :events accepts_nested_attributes_for :events end class Event < ActiveRecord::Base has_and_belongs_to_many :artists end And i'm trying to build a form for adding artists followed by their events, but i'm failing at that. Here's my view co...

Sanitizing video embedding code in Rails. What's a good solution?

What's your preferred method of sanitizing embed code entered in a form? In other words, is there an easy way of ONLY allowing users to embed video from YouTube and Vimeo for example? Do you use the Sanitize helper? If there is a proven solution to this I'd prefer to use it rather than reinventing the wheel. Thank you for reading my ques...

What should I do to make a Polymorphic Relationships in RoR?

I have a user table, and have a role column, that identify their role. Now, I want to add a "Student" table, that have the student's student number, and I also want to add a "Teacher", to store the teacher's salary. Both the Student and Teacher are the subclass of User. Now, I added a role column already in the User table, "T" = Teache...

No such file to load -- tasks/facebooker

WORKING UPDATE to solve this problem, I simply dragged the tasks/facebooker folder into lib from the venders/facebooker/lib/ directory. The migrations now function. I have a fully tested and working Rails app that won't deploy. Its running facebooker and working with restful authentication. In Capistrano I am getting the following m...