ruby-on-rails

How to use regex for utf8 in ruby

In RoR,how to validate a Chinese or a Japanese word for a posting form with utf8 code. In GBK code, it uses [\u4e00-\u9fa5]+ to validate Chinese words. In Php, it uses /^[\x{4e00}-\x{9fa5}]+$/u for utf-8 pages. ...

Ruby on Rails XML generation

I am attempting to build a simple method that creates an XML file from a database in ruby on rails. I feel like my code is right but I am not seeing all of the users in the XML. I am a complete newbie to RoR. Here's my code: def create_file @users = User.find(:all) file = File.new('dir.xml','w') doc = Document.new make = Ele...

Rails Associations, habtm? Polymorphic? Both?

In my Rails app I have three models, Projects, BlogPosts and Images. Projects and BlogPosts can have many linked images and an image can be linked to a Project, a BlogPost or both. What is the best way of setting up the associations to make this work in Rails? ...

Activerecode HABTM primary key problem

I have to tables that have a many to many relationship. I have created the correct table codesecure_project_tst_definition and it works. I can join rows together by calling the codesecure_projects << method on a TstDefinition object. The problem is that for some reason active record wants to use Codesecure_project_id as the id value f...

Fragment Caching with Memcached

Is there any way of using Memcached for fragment caching in Rails? ...

How do I add the condition "IS NOT NULL" to a Thinking Sphinx search

I'm using Thinking Sphinx for full-text search, following this video. I'd like to do the following: @articles = Article.search(params[:search], :conditions => "published_at IS NOT NULL", :order => :created_at) The problem is that this doesn't work. It seems that the search method only accepts conditions that are a hash. I've tried a ...

Portable Ruby on Rails environment

I got myself a new 8 gig USB key and I'm looking for a decent solution to have a portable RoR environment to learn on. I did the google on it and found a few possibilities, but I'm curious to hear some real life experiences and opinions. Thanks! ...

Drb and "is recycled object" exception

Hi all, I'm running in a strange issue. My controller calls a drb object @request_handler = DRbObject.new(nil, url) availability_result = @request_handler.fetch_availability(request, @reservation_search, params[:selected_room_rates]) and this Drb object is making some searches. but sometimes, in a linux environments, I get a "0xdba...

How can I find a model's relationships?

I want to, when given a particular model, return all the related models it is associated with. For example: class Dog < ActiveRecord::Base has_many :bones belongs_to :master end d = Dog.first d.associations #<== should return [Bone, Master] Is there a way to do this already without having to roll my own? Failing that, any sugge...

Apache cannot initialize Passenger. Broken pipe (32) when connecting to Application Pool

Hello - I have installed Phusion Passenger 2.0.3 on Apache 2.2.3 on Centos 2.6.18-92.el5 #1 SMP and I am getting the following on the httpd error log Cannot initialize Passenger in an Apache child process: Could not connect to the ApplicationPool server: Broken pipe (32) I have removed the modules that Passenger conflicts with as per...

rails: how to update a has_many :through relation via jQuery?

Hey guys! Sorry, if this is a noobish question, but I'm just getting started with Rails and jQuery. I have the following scenario: I have 3 classes: contacts, companies and contact_company_joins (ccj). For all three classes I created models, controller and views. Obviously, contacts and companies are connected via the join-table ccj (...

Building dynamic fields using ActiveRecord::Serialization.to_xml

I'm curious about people's experiences using AR's to_xml() to build non-entity fields (as in, not an attribute of the model you are serializing, but perhaps, utilizing the attributes in the process) from a controller. to_xml seems to supply a few options for doing this. One is by passing in references to methods on the object being...

conditional formating in rails partials

I am rendering a rails partial and I want to alternate the background color when it renders the partial. I know that is not super clear so here is an example of what I want to do: Row One grey Background Row Two yellow background Row Three grey Background Row Four yellow background sorry stackoverflow seams to prevent the b...

What's the best way to perform system tasks from Ruby on Rails?

I am building a small system administration web application (think Web-Min, but in RoR) and I need to be able to access system parameters from my Ruby code. For instance, I want to allow the user to change the hostname, time zone, or network config of the server. My current thoughts are to have a separate setuid script (Perl, Ruby, ?...

How to drop a validation set in included module?

Is there a way to drop a validation that was set in Rails plugin (or included module)? Let's say I have some model with module included in it: class User < ActiveRecord::Base include SomeModuleWithValidations # How to cancel validates_presence_of :something here? end module SomeModuleWithValidations def self.included(base) ba...

call a rails function from jquery?

Hey there, is it somehow possible to call a rails function or to access a rails object from within jQuery? I'd like to do something like: jQuery(document).ready(function($) { $('#mydiv').html("<%= @object.name %>"); }); OR jQuery(document).ready(function($) { $('#mydiv').html("<%= render :partial => "contacts" %>"); }); At the mom...

Content Voting Database and Application Design

How would you design a content voting mechanism that could be applied polymorphically to multiple models / classes. (in a ruby on rails context preferably, but others are fine) Given that instances of these classes can be voted on: - Article - Question - Product Voters should not be required to register. Best effort should be made to ...

Are there disadvantages to using a generic varchar(255) for all text-based fields?

I have a contacts table which contains fields such as postcode, first name, last name, town, country, phone number etc, all of which are defined as VARCHAR(255) even though none of these fields will ever come close to having 255 characters. (If you're wondering, it's this way because Ruby on Rails migrations map String fields to VARCHAR...

Keeping static files in server when deploying with Capistrano

I'm uploading files to my public/files folder of a Rails application on a constant basis through a web interface. I don't want to keep these in source control since they go for almost 2 GBs, so every time I do a cap deploy it will save those files away in releases/ and replace the directory with the pristine copy stored in the repositor...

Is Ubuntu an acceptable distro for running a production server?

I'm not a great Linux expert, but I'm comfortable running my Ubuntu desktop. I've also got a little experience running Ubuntu as a server as well, for my home network. At work, we're considering switching away from our current Solaris based setup to something Linux based. Our sysadmin is pushing for something like RedHat Enterprise or...