ruby-on-rails

Why do ActiveRecord callbacks require instance variables or instance methods to be prefixed with self keyword?

ActiveRecord has a few different callback methods used to simplify model logic. For example after_find and before_create methods. Consider this code example: class ExternalPrintingCard < ActiveRecord::Base belongs_to :user belongs_to :ph_user after_create :change_pin def change_pin self.user.randomize_printer_pin end ...

Paperclip for Rails: Can I access the model?

Let's say I have a model called Theme, which has several attributes setting interface colors. Theme also has a Paperclip attachment, which is a user-generated CSS template. I want to set up a processor to generate a final CSS file, inserting the interface colors into the user-generated template. To do this, I need to access the model dat...

Problem with Javascript onchange event in Ruby on Rails.

I nave this pice of code in index.html (upload controller) This an example. <p> <label for="picture_city">City:</label> <%= form.select :city, Picture::CITIES, :onchange => remote_function(:url => {:action => 'update_universities'}, :with => '') %> </p> When i go to upload/index the form loads well and no errors. But when i see g...

rails polymorphic nested form AssociationTypeMismatch

Unluckily I can't get this relative simple stuff to work.... :-( models: class User < ActiveRecord::Base belongs_to :role, :polymorphic => true class Admin < ActiveRecord::Base has_one :user, :as => :role class Dealer < ActiveRecord::Base has_one :user, :as => :role class Buyer < ActiveRecord::Base has_one :user, :as => :rol...

What should I check before my Ruby on Rails web site goes live?

As a developer new to Rails, I'd like to know what checklists seasoned Rails developers might have of things to check before putting a Ruby on Rails web site live. I am thinking that you should probably remove generated views that you aren't using, remove controller actions you don't need, remove default routes and so forth. I'm thin...

In ActiveRecord how do I use 'changed' (dirty) in a before_save callback?

I want to set my summary field to a sanitized version of the body field, but only if the user does not supply their own summary ie. params[:document][:summary] is blank. This appears to work fine if I create a new record, if I enter a summary it is saved, if I don't the body is used to generate the summary. However when I update the re...

Refactoring controller code for DRYness

Hi, I have numerous statements like these in both my create and update action of my controller: @company.set_preference(:api_username, params[:company]['api_username']) if params[:company]['api_username'] @company.set_preference(:api_password, params[:company]['api_password']) if params[:company]['api_password'] I'm wondering if how ...

Paperclip as a gem and Phusion Passenger (mod_rails) - can't find Paperclip

Hi, I'm using paperclip by thoughtbot for attachments to models and everything works fine on my development machine running mac os x and mongrel. However when I deploy may app to a debian machine running apache/mod_rails (2.2.5) I can't get it started. I get 'undefined method has_attached_file' (or 'uninitialized constant Paperclip' usi...

How to respond to HTML requests made via AJAX in Rails

I'm trying to write a Rails controller method that will respond to get requests made both "normally" (e.g. following a link) and via ajax. Normal Case: The controller should respond with fully decorated HTML using the layout. Ajax Case: The conroller should respond with the HTML snippet generated by the template (no layout) Here's the...

Phusion Passenger and database pooling

If my Rails application has the database pool size set to 5 (the default) in my database.yml file, and I'm running using Phusion Passenger, does that mean that there may be up to 5 database connections for each process that Passenger spawns, or is it 5 total across all processes? ...

Rails: Validates uniqueness of scoped by date

I have a Rails model that should only allow saving/updating of a model once per day per user. I have a callback to do the Find by user and date then add to errors but this is ugly and feels un-rails-like. I have the typical created_at / updated_at columns (and the time portion is significant/I need to keep it). So I figure I could eithe...

Open source equivalent to FiveRun' Tuneup

Is there an open source equivalent to FiveRun's Tuneup product for Ruby on Rails performance measurments? ...

link_to create and destroy a resource from a different resource

The code below is working but I want to know if there is a better way to do it. Is this the correct RESTful way to do this? Any suggestions would be helpful. The basic requirement is that I need a way to create and destroy a membership from places/show.html.erb class Place < ActiveRecord::Base has_many :memberships has_many :members...

Ruby On Rails Master-Slave Postrgres Databases

I am currently setting up a master-slave app using Ruby on Rails that needs to have a Master-Slave backend. I'm currently looking at using Slony for the replication component, and Masochism for handling the read/write connections to the different DBs. This is my first time setting up master-slave DBs with Ruby on Rails, and these are t...

Which Rails skeleton app is up to date with Rails 2.3.4?

Would appreciate any recommendations as a lot of skeleton apps I see are out of date. ...

passing in parent id to remote_form partial on item creation

I am still kind of fuzzy on controllers in rails, especially so because a lot of things seem to happen magically behind the scenes, and that's not happening in this case. So say I have a person model, which has many photos (using paperclip) and has many favorite quotes. The quotes can have the text, the attributed author, etc. In both o...

Smalltalk compilers that target either Java, .NET or Ruby

Looking for a Smalltalk compiler that given Smalltalk (Instantiations) will emit either Java bytecode, .NET CLR or Ruby. Not looking for porting utilities as I want to leave the application in Smalltalk. I have googled for solutions and ran across a company who had a website (http://www.smalltalkmigrations.com/) but it seems as if they ...

Handling mail: rails vs php vs perl vs ?

Hello This is my very first question in stack overflow and I am quite excited. Liked a lot the interface of this site and the buoyant community! I am building a rails app that receives text as an email and creates a post. I ask or your expert opinion on which is the best option to receive the mail message and process it? To send the ...

Do I need to encode strings (eg URL) I pass as a POST form parameter

Hi Do I need to encode strings (eg URL) I pass as a POST form parameter? Ie I want to pass a URL I have to my web application (ruby on rails) as one of the form parameters. So are there any potential characters in a URL/URI that would need to be encoded? Or perhaps rails would handle this anyway? ...

Hard coding routes in Rails

Let's say I have this: <%= link_to "My Big Link", page_path(:id => 4) %> And in my page.rb I want to show urls by their permalink so I use the standard: def to_param "#{id}-#{title.parameterize}" end Now when I click "My Big Link" it takes me to the correct page, but the url in the address bar does not display the desired pe...