ruby-on-rails

Polymorphic Paperclip Interpolations

I'm using the Polymorphic fork of Paperclip in Rails, but have been having some massive problems with regards to the overwriting of unique filenames. No matter whether I put a time-stamp (more on that in a second) or the id of the asset in the URL, if a file with the same name is uploaded subsequently, then the previous one is overwritte...

Paperclip not showing on the edit page

I am having some issues with paperclip, on my new page, I have a paperclip file that relates to aonther model. If I don't upload the keynote at the time of creating I can't go back and edit it on the edit page, I'm pretty sure its something todo with the fact that its related to another model. Here is my form partial <% form_for([@proj...

Adding validations without knowing the fields

My example form <% form_for @ad do |f| %> <%= f.error_messages %> <p> <%= f.label :ad_type_id %><br /> <%= f.collection_select(:ad_type_id, AdType.all, :id, :name) %> </p> <p> <% @ad.ad_properties.each do |property| %> <%= property.name %>: <% f.fields_for :ad_values do |value_field| %> <%= value...

Custom Rails Validation (Doesn't seem to be working)

Hey guys ive got the following Model for Accounts require 'net/http' require 'uri' require 'date' class Account < ActiveRecord::Base validates_presence_of :username, :password, :on => :update validate :valid_expiry_date, :on => :update def valid_expiry_date reply = Net::HTTP.get URI.parse("http://api.rapidshare.com/cgi-bin/rsapi....

Running Test framework as part of application

Hi, I would like to know if it is possible in rails to run some test cases through my application. I mean, i want show the test results to users. So i was thinking to be able to call my tests through a controller and put the tests output in a dialog. Imagine that i'm doing an application where before to apply a rule, i want to run some ...

Facebook api for different environments.

I've an application integrated with Facebook Connect. My application is deployed on different environments (production, staging, development) with different domains. Is there a way to set up Facebook app, so that it work with all my environments? Or should I create separate facebook apps for each env? ...

How to mark a link in a layout menu as "active" in rails?

I have a ul filled with links in my layout/application.html.erb and want the current location link be marked with class="active". Now I'm using: <%= link_to 'About Us', { :controller => 'aboutus' }, :class => "menu#{' active' if params[:controller] == 'aboutus'}" %> But it looks pretty nasty to me. Anyone has a better idea? ...

Formatting Dates in Rails 3.0

I'm trying to format a date in Rails 3 using the new syntax as described in the code: http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/date/conversions.rb by using the following syntax in an initialiser: Date::DATE_FORMATS[:my_format] = '%m %d %Y' I am then referencing dates in my view like so: co...

Get pixel color with Rails or anything else

I'd like to build a webapp in Rails in which I'd like to determine every pixel's color of a given image (JPEG). Is there any possibility to do that with Rails or JavaScript? The goal is to write an algorithm which determines the "middle color" of the image and uses it for background color of the site. Any suggestion would be appreciated...

Can't send flash message from Model method

Hello, I'm trying to prevent a record that has a relationship to another record from being deleted. I can stop the deletion but not send a flash message as I had hoped! class Purchaseitem < ActiveRecord::Base before_destroy :check_if_ingredient ... def check_if_ingredient i = Ingredient.find(:all, :conditions => "purchaseite...

Does a rails production.log store indefinitely?

If it doesn't, what's the half-life of it? It it does, where can find that information? On my server I found a few logs for each of my releases. But they only date back a few days. Specifically, I am looking for emails that were sent while my mail server was down two weeks ago. ...

How can you identify all events before and after a today in IRB?

I for the life of me can't figure out the correct syntax to show the count of events before and after today. Here's my awful and disgusting attempt: Events.find(:all).select {|e| e.date > Time.now}.size The trouble is the > or < operators don't work with Time.. :D ...

Rails shoulda and factory_girl setup

I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this: require 'factory_girl' Factory.define :user do |u| u.mail '[email protected]' u.pass 'secret' end to my test/test_helper.rb I'm getting this error: /test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)...

Forms blank when rendering a partial when using a collection of objects. Help!

Alright, I know my title is a little obscure but it best describes the problem I am having. Essentially, I have a list of users, and want to be able to edit their information in-line using AJAX. Since the users are showing up in rows, I am using a partial to render the data and the forms (which will be hidden initially by the ajax), ho...

helper methods not being found

I've got a CopiesHelper module with a method cc. In my ApplicationController, I have helper :all helper_method :cc #just tried putting this in recently If in another one of my Controllers, I try using the cc method, I get undefined method 'cc' for #<OtherController:0xblublublublub> Am I missing a step here? ...

Arel: How to cleanly join multiple conditions with OR?

In my Rails app, I loop through an array to create a list of conditions that must be joined by OR. Below is the basic flow of how I currently do so. conditions = nil set.each do |value| condition = value.to_condition conditions = conditions ? conditions.or(condition) : condition end Obviously, it's not beautiful, but I still don't...

attachment_fu configuration

I have a model called photo with this: has_attachment :content_type => :image, :storage => :file_system, :max_size => 10.megabytes, :resize_to => '800x600>', :thumbnails => { :thumb => '100x100>', :large => '450x600>', :medium => '64x64'...

Rails paginate array items one-by-one instead of page-by-page

Hi Guys, I have a group of assets, let's call them "practitioners". I'm displaying these practitioners in the header of a calendar interface. There are 7 columns to the calendar. 7 columns = 7 practitioners per view/page. Right now: if the first page shows you practitioners 1-7, when you go the next page you will see practitioners 8-1...

ruby on rails, restricting access to public directory

I need to prevent access to public directory with .htaccess kind of mechanism. It means that hitting http://localhost:3000 should ask for credentials before it shows anything else. Is it possible? ...

Rake uninitialized constant RDoc::RDoc

When ever I run make I get this 'uninitialized constant RDoc::RDoc' error rake -T (in Main) rake aborted! uninitialized constant RDoc::RDoc C:/Ruby186/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile' (See full trace by running task with --trace) --edit Running --trace it ...