ruby-on-rails

Rails - Should an object's types be in its own model?

I have a contact, and contact has_many :phones. The phones table has a column named, phones_desc, where I want to include the type of phone number the user has saved. My question / Best practice Should I provide a select with manually provided options (such as "mobile", "work", "home")... -or- ...create a new model named phones_type...

Rails: checking modified fields

First, I've generated scaffold called 'item' I'd like to check which fields of the item are modified. and I've tried two possible attempts, those're not work tho. First Attempt! def edit @item = Item.find(params[:id]) @item_before_update = @item.dup end def update @item = Item.find(params[:id]) # compare @item_before_update a...

Does dependency injection exist in Rails?

Does the fact that Rails have an MVC approach mean that is has dependency injection? Or is there a reason that we don't talk about dependency injection in Rails? If Rails does have dependency injection, what does it consist of? ...

Rails 3 : Anticipating migration for 2.3 beginners

I am a beginner in Rails. I use 2.3.X. I just saw Rails 3 is pre-released [edit: now in release candidate!]. I will most probably eventually switch to it. What are the common coding habits in 2.3 I should not take, so that the switch is as smooth as possible ? Edit: I've done my homework and read the Release notes. But they are far f...

Rails - in what order does dependent => destroy follow?

Say i have this fictitious example below class Server < ActiveRecord::Base has_many :clients,:dependent => :destroy after_destroy: delete_server_directory end class Client < ActiveRecord::Base belongs_to :server before_destroy :copy_some_important_stuff_from_the_server_directory_before_its_too_late end So when i use server.de...

SSL and authentication across multiple domains

I am building an app with Ruby on Rails which allows users to sign up and create their own subdomain: joebloggs.myapp.com So at the very least I need a wildcard SSL certificate to handle when users are passing sensitive data (authentication, payment etc). In addition, we are allowing users who want to, to map their own domain to thei...

Use nested controller or declarative authorization for admin action?

Say, I've an app with multiple models:posts, blogs, todos etc and I want an admin to edit, delete all users posts, blogs, todos, do I create a nested admin controller for each or use declarative authorization to setup an admin account that can edit/destroy the users, posts etc? I understand this has no right answer, I'm just looking for...

Ruport vs. Prawn considering long-term use

I want to add reporting capabilities to my Rails application and I'm struggling quite some time now on which reporting software to use to create my PDF documents. Until now I'm pretty sure that either Ruport or Prawn are the best way to go. After experimenting with both of them I find that they both are very powerful and quite universa...

updating wrong value to database

Hey all, I'm just trying to increment a record by 1 starting at 2000, when a new record is created upon clicking on the create action to create a record: if resource_model == Student then @resource.testing_id = id + 2000 end So if the record has an id of 1, I assume that the testing_id will be 2001. But instead it returns: 2147483647 ...

ActiveRecord find query with join only doesn't include data from joined table

I have two tables: keyword_reports and keywords (with relevant AR models). keyword_reports has a keyword_id column, which I'm using to join the keywords table like so: KeywordReport.find(:all, :joins => :keyword, :conditions => {:page_id => 10}) which correctly pulls back records for keyword_reports, but doesn't include the data from...

Model a person-to-person relationship in Ruby-on-Rails using has_many :through

I would like to model a person's relationship to another person, where the relationship isn't necessarily hierarchical (i.e. friends & colleagues, rather than parent & children) and I am interested in capturing more detail about each relationship (e.g. notes, type of relationship, date established). Finally, I would like to use the act_a...

ruby - how to encrypt text

Hi, I need to encrypt a string (from a text area) that will also be decrypted later on when it is displayed. I'm not to concerned about it being majorly secure, but just don’t want to store the data in plain text format. Does anyone have any suggestions on how to do this easily in rails? Thanks, Jon ...

How do I implement a Rails model named "series"?

The singular and plural forms are the same and I get an undefined_method error when trying to hit the New method. I realize why and I'm aware that the easiest solution would be to use another name. I'm also aware that I could create a custom inflection, but what? The problem is that I REALLY need URLs like /series, /series/1 etc becau...

Most code-efficient way to handle data stamped as "final" vs. data that may incur changes.

Hi there, I have several models whose records AND associations can have two states that must be persisted. Final, and Draft. Here's a little more detail: If the model is "application form" and the user submits a final application form, then I need to store and be able to retrieve that final application form. If, at a later date, the u...

Setting up a mutual belongs_to in Ruby on Rails

I'm creating a wiki. Each Article has_many Revisions, and an Article belongs_to a single current_revision. So in the database, Articles have a single reference to a Revision's id, and Revisions each have a single reference to the Article they belong to. Before I continue, does this seem like a sane way to do things? It strikes me as ...

Why is class_inheritable_reader in ActiveSupport not documented?

Hi there, Pulling my hair out trying to figure out where class_inheritable_reader is documented in Rails. A Google search revealed its existence, and looking in the gem itself ya find the method: def class_inheritable_reader(*syms) syms.each do |sym| next if sym.is_a?(Hash) class_eval <<-EOS def self.#{sym} ...

Writing functional tests for facebooker controller?

Anyone have any tips for best practices for mocking out facebook requests in functional tests? Is it just as simple as adding all of the proper params to the request? Is there a way to stub those out? I'm using facebooker, which comes with a mock service: # A mock service that reads the Facebook response from fixtures # Adapted f...

rails - DRY respond_to with repeated actions

In one of my rails controller, I must respond to several types of formats, so I use the typical respond_to chain: respond_to do |format| format.html { ... } format.mobile { ... } format.jpg { ... } format.xml { ... } format.js { ... } end Usually that the { ... } part is repeated on several formats. What is the best wa...

Can't install Ruby on Rails on Wamp

I followed this tutorial: http://stackoverflow.com/questions/2025449/how-to-install-ruby-on-rails-alongside-wampserver After adding D:\wamp\ruby\bin (my wamp folder is in D:) to my Path and write gem install rails in the command line I get 2 error which says that the following files couldn't be found: SSLEAY32.dll zlib.dll Here is t...

Beginner's question on has_and_belongs_to_many

Hello! My models look something like this: Section has_and_belongs_to_many :blogs Blog has_and_belongs_to_many :sections has_many :posts Post belongs_to :blog I can get all Posts from a certain Section's Blog by doing this: section.blogs[n].posts My question though is how to get all Posts connected to a Section (via a Blog)? I...