For my RubyOnRails-App I have to start a background job at the end of Capistrano deployment. For this, I tried the following in deploy.rb:
run "nohup #{current_path}/script/runner -e production 'Scheduler.start' &", :pty => true
Sometimes this works, but most of the time it does not start the process (= not listed in ps -aux). And the...
I want to define a class method that has access to a local variable. So this would be different for each instance of the class. I know you can make a class method dynamic with lambda like when you use it with named_scope. But can this be done for values that are specific to an instance?
In detail it is the has_attached_file method for...
I'm trying to get the output of the query 'SHOW TABLES FROM database_name' into an array using the ActiveRecord database connection. I can't seem to figure out how to do this. can someone please enlighten me?
-C
...
I have a datetime column in db that I want to transform into a simple date when I show it to users.
How can I do that?
def shown_date
# to_date does not exist, but is what I am looking for
self.date || self.exif_date_time_original.to_date
end
...
I'm using Mongrel in development mode for my rails app. I noticed that regardless of the what the actual HTTP status should be, it is being returned as 200 to the browser. In production mode, the status is correct.
For example, when the record it is not found, the app displays the correct (not found) view, but the status sent to the br...
I periodically fetch the latest tweets with a certain hashtag and save them locally. In order to prevent saving duplicates, I use the method below. Unfortunately, it does not seem to be working... so what's wrong with this code:
def remove_duplicates
before = @tweets.size
@tweets.delete_if {|tweet| !((Tweet.all :conditio...
I'm using Hpricot for traversing an XML packet. For each node I'm on, I want to get a list of the immediate children . However when using
(current_node/:section)
I'm getting ALL descendant sections, not just the immediate children.
How can I get around this?
...
Considering the following resources with their corresponding relationships:
Site
has_many :page
has_many :groups
has_many :projects
Group
belongs_to :site
has_many :pages
Project
belongs_to :site
has_many :pages
Is it good to make Page model polymorphic or leave individual foreign keys?
**Scenario 1 (Polymorphic)**
Page
pa...
Is there a rails-like way to divide results from an activerecord query? For example, I did @results = Items.find(:all), but I want the top half of items from @results to appear in a line item under <ul class="part1">, and the other half of them to appear under <ul class="part2">.
<ul class="part1">
<li><a href="#">result["name"]</a...
I'm creating a program which will be examining images which are uploaded by the users logged in. I have the RMagick code written up to do the examination (basically finding out if a pixel black is in an image), but I don't know how to write the unit tests for this model.
Currently I'm using paperclip to attach the uploaded file to the ...
In my rails application, I render a partial on multiple pages, and in that partial is a variable. So currently, lets say I have 5 pages that render :partial => "partialname", and inside of partialname is @variable.
Can I have it so that partialname has its own action with @variable instantiated inside, rather than having @variable be...
Hi all,
I'm currently writing an app that pulls all the tweets from twitter with links in them and puts them into our searchable database.
Our database tables look like this:
Tweets
content
tweet_id
Links
url
title
count
User
username
user_image
We'd like to be able to search through the tweet.content column for a s...
I have been trying to figure out a solution but nothing has really presented itself to work. I am building a system that sends out emails (among other things), and I have been trying to figure out a way to have the queuing of messages work. I would like to provide the user a (somewhat) accurate count of the messages sent so far. I was th...
Hi there,
I am trying to figure out the most straightforward and safe way to count the number of active sessions using a memcached storage option. With DB based session storage, I can just count the number of rows in the table but can't do the same thing with memcached.
Thanks,
Vikram
...
Hi,
I need several RSS feeds in my app. They are in a way similar to existing actions but with less options (no will_paginate, no sorting, only the most recent 20 results). So for example I have one action which shows all items tagged "amazing" and I also need one feed which shows the latest items tagged "amazing".
My question: Is it b...
I try to access a file with open-uri over an https connection. Unfortunately somethings wrong with the certificate, I get a certificate verify failed error. I can't do anything about that, so I have to bypass the verification.
I found this answer
I don't want to / can't change the oen-uri.rb on the server, and I'm running Ruby 1.8.6.
...
I am thinking of working on a Rails application that uses PostgreSQL. I have some questions before I am comfortable using Rails:
Is PostgreSQL support in Rails less superior than, say, MySQL.
Would it feel any different if using PostgreSQL?
Are there any cases where using PostgreSQL fail to work?
Thanks.
...
I'm learning Ruby on Rails and doing the contactlist thing, 20 minute blog and so on, but I am concerned about using RoR with existing non-MySQL databases. I know RoR can communicate with non-MySQL; in fact, I am using jRuby on Rails so I can use JDBC.
My question is how RoR works with existing database. Do I lose all the benefit of u...
If you come across classifieds websites like craigslist, oodle, kijiji,... everything is a classified, when you are posting a classified, they show different form fields depending upon the category one selects. For example, if you are posting a classified about Car, they show make, model, interiors, etc... How do you think data is handle...
Where is the best location to put a plain old Ruby class in a Rails application? I'm not sure if it should go in the helper, model, or controller folder or should I create another folder to handle Ruby classes.
...