Why is the following happening, and how can I sort it?
On OS X Leopard (v10.5.6):
$ ./script/server
Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update --system` and try again.
$ sudo gem update --system
Updating RubyGems
Nothing to update
...
I have done some work with Ruby on Rails but am still not comfortable writing a Rails app from scratch. My problem is that I am not able understand how to get the right model going when trying to write the application from scratch. I thought seeing the code of a complete existing application may help but am not sure. What should be the w...
Update: This gem DOES install with sudo rake gems:install. The problem is with loading. For instance, when I run script/console, it throws:
no such file to load -- outoftime-noaa ...
Even though sudo rake gems:install just installed it. I'm not sure if this matter, probably does, but it throws this error twice.
-=-=-
I'm looking...
Someone who understands how rails caching works can really help me out here. Here's the code, nested inside of the Rails::Initializer.run block:
config.after_initialize do
SomeClass.const_set 'SOME_CONST', 'SOME_VAL'
end
Now if I run script/server and make a request, everything is dandy. However, on the second request to my Rails ap...
Ok, suppose I have Ruby program to read version control log files and do something with the data. (I don't, but the situation is analogous, and I have fun with these analogies). Let's suppose right now I want to support Bazaar and Git. Let's suppose the program will be executed with some kind of argument indicating which version control ...
I am doing a very simple search on my DB using acts_as_ferret. I put this in my "Venue" model:
acts_as_ferret :fields => [:name, :city]
And this is in my controller search action:
@t = Venue.find_by_contents(params[:search]+'~')
and then I just render the results.
render :text => @t.to_json, :success => true, :status => :ok
I...
I need to delete a bunch of subdirectories that only contain other directories, and ".svn" directories.
If you look at it like a tree, the "leaves" contain only ".svn" directories, so it should be possible to delete the leaves, then step back up a level, delete the new leaves, etc.
I think this code should do it, but I'm stuck on what ...
If I have some text that I want to print out on a page, but only want to print say the first 100 words before eclipsing it... what's the easiest way to do this?
...
We're preparing to rewrite/restructure our corporate website and are looking for a CMS to back it. I need the CMS to provide a way of giving certain users in our company control over certain sections of the web site (i.e., allow our Marketing department to update press releases, our HR department to update job postings, etc). It should a...
I'm using Merb and DataMapper with a MySQL db. I want to access the database name, user, and password from a Rake task for my Merb app. I guess I could YAML.load() the the database.yml, but that seems ugly. Any ideas?
...
What is the best way to test a model that is using a different database connection in Rails. For example I have a model FooBar that is read only:
class FooBar < ActiveRecord::Base
establish_connection configurations['foo_bars']
# ...
end
Are there any good conventions, hacks, or plugins out there?
...
This code works, of course:
@x = { :all => { :x => 1, :y => 2 } }
But this doesn't:
@x = { :abc, :all => { :x => 1, :y => 2 } }
Is there any way to do what I want here? i.e. I want two keys in a hash to each refer to the same (copy of a) value. But I only want to specify the value once.
...
I have seen a lot of talk regarding ActiveRecord Migrations and whether or not they should be used to change data within your application, some people saying yes some saying no. My question is if you are not using Migrations to do this then what are you using? Just another script that you write?
I am after suggestitions on alternative w...
So I've got two models, State and Acquisition. State has_many Acquisitions. I felt like an autoincrementing integer primary key for 51 records was rather silly. So I altered the model for the State to be the PK (State being the two letter abbreviation; I'm not storing the actual state name anywhere:
class State < ActiveRecord::Base ...
This is useful if you are trying to create class methods metaprogramatically:
def self.create_methods(method_name)
# To create instance methods:
define_method method_name do
...
end
# To create class methods that refer to the args on create_methods:
???
end
My answer to follow...
...
Hello,
I have a User model and a Friendship-Model.
class Friendship < ActiveRecord::Base
belongs_to :sender, :class_name=>'User', :foreign_key=>'sender_id'
belongs_to :receiver, :class_name=>'User', :foreign_key=>'receiver_id'
validates_presence_of :receiver_id, :sender_id
validates_associated :receiver, :sender
end
class Use...
I have a URL of form http://www.example.com?foo=one&foo=two
I want to get an array of values ['one', 'two'] for foo, but params[:foo] only returns the first value.
I know that if I used foo[] instead of foo in the URL, then params[:foo] would give me the desired array.
However, I want to avoid changing the structure of the URL if ...
I have a PostgreSQL DB on a remote VPS server (CentOS 5) and I'd like to connect to have a Rails application connect to it from my local Mac laptop. On my laptop, I have the ActiveRecord PostgreSQL adapter installed -- postgres (0.7.9.2008.01.28).
I read in the PostgreSQL docs:
The password-based authentication methods are md5, cryp...
Is there an easy way to run a single migration? I don't want to migrate to a certain version I just want to run a specific one.
...
I'm looking for a way to call a single Capistrano task to perform different things to different roles. Is Capistrano able to do this, or do I have write a specific task for each role?
...