ruby-on-rails

Disable rails class_caching mechanism for Time.now?

Hey there, I'm currently fighting with the rails class_caching mechanism as I need to return a file path that changes discrete over time. It is used to constantly change a log file path after the amount of GRAIN seconds and returns a fully working timestamp: GRAIN = 30 def self.file_path timestamp = (Time.now.to_i / GRAIN) * GRAI...

Ruby on Rails: Get the controller and action name based on a path

I am trying to get the controller and action name based on a path. I have a route: map.resources :permissions I thought that I could use: ActionController::Routing::Routes.recognize_path "/permissions/1" To get a hash like: { :controller => "permissions", :action => "show" } The actual hash that comes back is: { :controller => ...

Regular expression + Ruby On Rails

I would like to validate my users, so they can only use a-z and - in their username. validates_format_of :username, :with => /[a-z]/ However this rule also allows _ - and capital letters. How do I only allow letters, numbers, _ and -? ...

observe_form url confusion

i cannot seem to get observe_form to call a particular action i have a route defined map.resources :charges, :collection => {:charge_total => :get} my controller class ChargesController < ApplicationController def charge_total return 'foo' end end my view: i have tried both... observe_form form_id, :update => :charge_tota...

multiple attributes to save as blob data type in mysql and retrieve in ruby on rails

I have got about 9 combo box in registration form and i would like to save all of them as blob data type in mysql and retrieve them in edit form my view form looks like the following <%= select("pcs","pc_info[HDD]",options_for_select(["---Select---","20GB","40GB","160GB","250GB","Other"]"), {:style => "width:142px"}) %> </td> <%= se...

scriptaculous slider not working with bundle-fu

We just upgraded our rails version from 2.1.2 to 2.3.8 then suddenly our javascript sliders stopped working. I looked at previous commits, codes, etc and saw nothing changed that might affect the slider.js I finally hit the nail on the head when I randomly commented out bundle-fu here: <%# bundle :name => "javascript_bundle" do -%> ...

Configure Memcached with Rails 3

Hi :) I'm having problems trying to use Memcached in a Rails 3 Application ... My question is quite simple : How I'm supposed to configure Memcached to make it works with Rails 3 ? Thanks for your help ! Edit: It looks like the object isn't correctly deserialized by the Rails.cache.read no matter :raw => true or :raw => false but th...

Rails 3 multiple accounts authentication solution

I am searching for a working solution of authentication on Rails 3 with the following features: account types: standard login, facebook connect, openid, oauth one user may have (and link) multiple accounts (EG a user attach both Wordpress and Google OpenID accounts) A working example of Rails app implementing them would be perfect. ...

validates_associated model with condition

hello frens. I have the following validates_associated scenario class Parent include Mongoid::Document validates_associated :son validates_associated :daughter end when i create a parent, either of son or daughter is only created not both. Now my problem is, when i try to create parent with son, then validation fails due to daug...

RoR select_tag selected value

Hi I'am using select_tag and I want to pass selected value in href :onchange I couldnt fetch the selected value Please guide me how to fetch the selected value and pass in href I'am using following code <%= select_tag "name", options_for_select(@user.names.map {|c| [c.firstname,c.id]}), :onchange =>"document.location.href='/n...

Exception `ArgumentError' in activerecord-oracle_enhanced-adapter

Hi. I have a rails app under Oracle, Apache and Phusion Passenger. I use activerecord-oracle_enhanced-adapter-1.3.0 and ruby-oci 2.0.4. Every time I made a request, this error appear, even if the request is served correctly. Apparently nothing goes wrong, but my boss is very nervous about it and I didn't find any clue on Google about thi...

Using ActiveRecord::Dirty changes method in a model that has many relationships

Hi! I have a model that I am attempting to apply optimistic locking to. If the user has a stale record I need the system to display what they entered and ask them to try again. I have attempted to use the changes method, which works. My issue is that the model has many different levels of related models, that are all submitted within the...

How to copy file across buckets using aws-s3 gem

The aws-s3 documentation says: # Copying an object S3Object.copy 'headshot.jpg', 'headshot2.jpg', 'photos' But how do I copy heashot.jpg from the photos bucket to the archive bucket for example Thanks! Deb ...

Bundler installing gems in wrong location

This is kind of bizarre. Any time I do a bundle install, Bundler installs all my gems to the path #{RAILS_ROOT}/json_pure/ruby/1.8/gems. I copied the Gemfile directly from another application that works perfectly, and I don't think I've modified any other configuration. Any ideas what could be going on here? Not sure if it helps, but my...

How to add Rich Text Editor to display code snippets

Im working on a Rails based application where I have the need to allow the user to format the text he enters and I would also like a way to highlight code snippets the way Stackoverflow does when I enter a code snippet. Are there any plugins that do this. And I would also like to know which is the RTE that is recommended and would be ...

How to add condition "LIKE ? %something%" to the product title to this join

Product.find(:all, :conditions => { :companies => { :malls => { :id => 1},:products => {:title => "nexus one"} }}, :joins => [:company => :mall]) ...

Ruby on Rails: what is the performance of .constantize?

Let's say I have Model.find(something) and variable.constantize.find(something) what are the performance differences? I mean, not having the extra step will obviously be faster, but under the hood, is there that much of a difference? Refactoring 12+ methods from different controllers to one method with a constantize is AMAZING! ...

RHTML to string - rails

Hi, everyone. In my rails application my models have a to_html method. This method is called in one of the views so the model's attributes can be displayed properly regardless of their classes (because all of my classes implement that method) That is a neat solution, but one thing bugs me. I need to write this html code inside the doub...

Object refuses to save changes in Rails IRB

Good morning all, I've got an association that I'm working on, and for some reason, I can't get it to save changes to the object in question when I'm debugging it in IRB. I was wondering if anyone could point out my problem. Here is the association: class User < ActiveRecord::Base has_and_belongs_to_many :affiliates has_one :mana...

Flash messages in Rails getting carried over to the next page

Hi, I am displaying error and notice messages in my application with a helper method as shown below. def display_flash_content [:error, :notice].map do |key| collection = flash[key].blank? ? [] : (flash[key].respond_to?(:map) ? flash[key] : [flash[key]]) collection.map {|item| content_tag(:div, item, :class => key.to...