ruby-on-rails

Reopen autoloaded class from within a Rails 3 plugin?

I have a Rails 3 app that defines some classes like normal. I am trying to figure out how to reopen one of those classes within a plugin (generated by "rails generate plugin ..."), and have both of the files (the file in the app itself and the file in the plugin) automatically reload on every request in development mode. A simple exampl...

Rails 3- fixing juggernaut involving template and JS generator

Hi, I'm using the original Juggernaut (not Juggernaut 2) with Rails 3. In the lib/juggernaut.rb, it breaks due to not being able to find @template. According to this other post, @template is not provided in controllers in Rails 3. How can I fix the following code, so that it can run smoothly with Rails 3? (Here's a link to the origin...

In Rails, what is the difference between installing a gem, and then rake gems:freeze into the vendor folder vs installing it as a plugin?

Both methods put the gem into the project's folder to be a self-contained project. Is there advantage / disadvantage of these methods or one better than the other method? (the project is a Rails 2.2 project, so can't use Bundler) ...

One big object or one small plus one big info object?

Hi, For a Ruby on Rails app, I'm having this Movie object which has several attributes. Pretty much every page needs to compare some movies to a full list of these movies sorted by ratings, so I used to cache this big sorted list. It was useful, because I could directly use this list of Movies and all their attributes without any other ...

Ruby on Rails - Clean up url parameters

I have a Rails app set up so that when a user uploads an image, it is sent directly to Amazon's S3. I have to specify a redirect address in the form code. After the image is finished uploading, Amazon redirects the user to www.redirect_address.com/?bucket=[BUCKET]&key=[KEY]&etag=[ETAG] I need the bucket and key info to process the image...

Searching polymorphic associations in Rails

Hello all, I have a need in my app to allow users to bookmark a post. They should only be able to create one bookmark per post. I've set up my polymorphic association like so: class Post < ActiveRecord::Base has_many :bookmarks, :as => :bookmarkable end class Bookmark < ActiveRecord::Base belongs_to :bookmarkable, :polymorphic =...

rails: data being deleted on page reload

I have a method in my application helper that is meant to deactivate a task in my database. Application helper: def link_to_destroy_task(task_id) Task.find(task_id).deactivate end Model: def self.deactivate() update_attribute(:active, false) end View: <ol id="tasks"> <% @Tasks.each do |task| %> <%content_tag_for...

How do I create an ajax toggle for an attribute in Rails?

I have a view of a Model, and there is an attribute 'direct' which can either be 'true' or 'false'. Am wondering if there's a standard way or even a plugin/gem or just good suggestions on how that can be toggled on or off in the view. I found myself writing alot of logic in the view so stopped and sought some guidance. A simple versio...

Authlogic - separate tables for users and sessions

Hi all, I'm implementing Authlogic and attempting something i haven't done before. I basically have two tables: account_holder: this has all the standard columns you'd expect...email, crypted_password, etc. session: this has account_holder_id, persistence_token, last_request_at, last_login_at, etc. Basically i was hoping to store a...

How and where to define common code that will be invoked from various controllers - Rails v3

I need to define some common piece of code that can be invoked from different controllers(not view). Is there a way to do that in Rails v3? I have defined the code in ApplicationHelper and tried to invoke it using @template.<helper_method> and ActionController::Base.helpers.<helper_method> But it does not work? ...

rspec model associations with Factory Girl

I am trying to create a rspec test for a model for States. This state model has an association to a Country model. My factories look like Factory.define :country do |country| country.name "Test Country" end Factory.define :state do |state| state.name "Test State" state.association :country end I have made a functional state...

In Rails, if "gem install ___" installs 6 gems total, will installing as plugin require installing the other 5 gems manually?

If installing a gem using gem install ______ actually install 6 gems, because of the dependencies, then if the gem is installed as plugin by script/plugin install git://github.com/author/____.git or script/plugin install _____ then we to manually install the gem it depends on? Does it matter if it is the later form, where it d...

Rails RSpec Tests for a has_many :through Relationship

I'm new to testing and rails but i'm trying to get my TDD process down properly. I was wondering if you use any sort of paradigm for testing has_many :through relationships? (or just has_many in general i suppose). For example, i find that in my model specs i'm definitely writing simple tests to check both ends of a relationship for r...

What is the canonical Rails way to collect & store physical or mailing addresses?

I need to collect and store mailing addresses in a Rails (2.3) app. Is there a Rails way to do mailing addresses? For example, I would do f.date_select to generate a series of dropdowns to handle dates, which are then stored in the database, which I defined in schema and migrations as t.datetime "foo". I would consider that the canonica...

why does the uniq! method work but sort! not on this array in rails?

Here is how I created an array: @companies_with_email = Company.contact_emails_date_sent_gt(@monday). contact_emails_date_sent_lt(@friday). find(:all, :select => "distinct companies.* ") || [] @companies_with_call = Company.contact_calls_date_sent_gt(@monday). ...

Rails/ActiveRecord: Get a record made *AFTER* a particular date

So currently I have an issue where I am populating a database from xml files through my client's API. Each record has an expiration date in it, with the following format: <offer_ends_at>2010-10-20T07:59:59-04:00</offer_ends_at> Now, I need to run a query where I only get records that have an expiration in the future. My current code i...

[Rails] Custom User Sessions

I'm trying to make a stripped-down user sessions system, and tried to model it to be similar to authlogic. class UserSession attr_accessor :username def initialize(params={}) @username = params[:username] end def new_record? true end def self.find return nil if session[:username].nil? UserSession.new sessi...

In Rails 2.x, what is the difference between "rake gems:unpack" and "rake gems:freeze"?

It seems that both methods can freeze a gem into the vendor directory, but rake gems:unpack requires the gem to be listed in config/environment.rb as config.gem '<name of the gem>' before the rake is done. On the other hand, rake gems:freeze requires installing the gem gemsonrails first, and uses the syntax rake gems:freeze GEM=haml and...

In Ruby / Rails, why "gem server" says haml depends on maruku and yard but "gem list" doesn't show these gems?

If I run gem server and go to localhost:8808, one of the entry is haml and it says it depends on maruku and yard haml 3.0.22 [rdoc] [www] - depends on maruku, yard. An elegant, structured XHTML/XML templating engine. Comes with Sass, a similar CSS templating engine. Executables are css2sass, haml, html2haml, sass, sass-convert. b...

Voting with Ajax in Rails

I'm trying to allow users to vote a record up/down with Ajax. I'm using the vote_fu plugin for the voting functionality, and everything works fine without Ajax. I'm now trying to figure out the best way to implement the asynchronous functionality with unobtrusive javascript. What I'm doing now is having two buttons, "Up" and "Down", suc...