ruby-on-rails

String operation in ruby for credit card number

Working on a rails project where there's an order confirmation string with a credit card number with all but the last four digits starred out. What's the proper way to do a string substitution? What's the operation to get this credit_card_number = "1111111111111111" to this? credit_card_number = "************1111" Thanks, Kenji ...

ruby on rails add functionality to model property change

In my rails model, I have a decimal property called employer_wcb. I would like it if, when employer_wcb was changed, a dirty bit was set to true. I'd like to override the employer_wcb setter method. Any way to do so (in particular using metaprogramming)? ...

Rails Routing Error

Weird error. I'm a newby to rails. From a new install of rails I connected to an oracle db and then ran: jruby script/generate scaffold job oid:integer userid:integer name:string status:integer Without doing anything else I started up the server and entered a new job and then I get this error: Routing Error job_url failed to genera...

rails routes question - how to take all parameters to end of URL?

Hi, In the rails config/routes.rb file, how do I ensure that the first route here takes all characters after the initial /site and uses this for this route (assigning it to :path). map.connect 'sites/:path', :controller => 'xxx', :action => 'yyy' map.connect ':controller/:action/:id' In other words how to avoid any URL that goe...

How Do I Prevent Email Attachments from Rendering Inline using ActionMailer

I am using the following code to send an email with a pdf attachment: class StudyMailer < ActionMailer::Base def notify_office(study, sent_at = Time.now) subject "Email Subject Goes Here" recipients '[email protected]' from "#{study.sender.full_name} <#{study.sender.email}>" sent_on sent_at body :s...

Validating an Excel file in a Rails app

I have a Rails app which allows users to upload Excel files which need to be validated according to some pre-defined rules. For eg. sheet 1 contains two columns, a numerical id and a name; sheet 2 contains three other columns etc.. Are there any Ruby gems/libraries that can help in doing these validations? ...

Explicitly inherit from a class in the base module.

I have a class that inherits from class User. eg class MyClass < User end In my code base I have a class user class User end However I also have a plugin that provides a User class in a module TheirModule::User. This is a plugin that my application is tied to and I cannot remove it at the moment, however that is wh...

is there a profiling gem/plugin for Ruby on Rails?

Hi, is there a profiling gem/plugin for Ruby on Rails? That is, where I can then specify the point in a request I want to act as milestones points for a time to be taken, and place them stategically. Then ideally the plugin then works out and displays how the overall response time was made up... Tks ...

ruby template erb

I have a layout.html.erb file w hich should act as a common file for all the pages to decorate as shown below. <%= render :partial => "layouts/header" %> <%= render :partial => "layouts/leftsidemenu" %> <body> <%= @content_for_layout %> </body> <%= render :partial => "layouts/footer" %> How can I configure this rails frame...

Is there any rails plugin like formtastic that makes show and index views easier to code?

I use formtastic to create new and edit forms for my resources. with something like f.inputs it fetches and displays all my fields automatically. I would like to know if there is something similar that makes life easier to write the index and show views. I tried using formtastic with 'disable' to show a readonly form but that's not onl...

controller and restful application

Hello, I have a MVC web application (Ruby, Rack, Apache) and I want it to be restful. I have a dispatcher that will get incoming URI and call the appropriate controller. In my mind, a controller is there to handle every actions linked to a single model, I am wrong ? The thing I am not sure about is a case like the following: If a user h...

Ruby on Rails Accessing hidden values from controller

hi all, how do i access hidden value fields from the controller class. my hidden value field is <input id="user_id" name="user.id" size="30" type="text" value="<%= @user.id %>" /> currently i am trying to access with @user.id , @user = User.find(@user.id) but its generating error like " Called id for nil, which would mistakenly ...

Problem saving rails marshal in sqlite3 db.

This is what I tried f = 1.2 f = Marshal.dump(f) #\004\bf\v1.2\00033 after that I tried to save this f into text column and this is an error I got. ActiveRecord::StatementInvalid: SQLException: unrecognized token: "fϾ1.2 33" (Ͼ is male symbol, but I can't find one). ...

Can I implement rails setter and getter for attributes for db columns.

In rails we can access db column through attributes rails provided, but can we change this ? for example I have db with name column could I implement something like. def name "sir" + name end I tried it, but it result in stack overflow. There is a way to accomplish this. more question, Is there any difference between name and self....

TeamCity returns No such file to load -- rubygems (LoadError) but terminal runs fine

I've just setup 3 osx agents to run the CI for our ruby project. 2 of these agents are running our specs perfectly, starting their agents correctly etc. The third machine constantly returns No such file to load -- rubygems (LoadError). I have navigated to the work folder (the check out folder for the project) and i can run the commands i...

Relation between two single-table inheritance models

Hi, I have the following two models class ContactField < ActiveRecord::Base end class Address < ContactField end class Phone < ContactField end and class Contact < ActiveRecord::Base end class Company < Contact end class Person < Contact end I want one contact, no matter is it Company or Person, to have many ContactFields(Addre...

How to force fragment cache on rails from cron schedule?

Is there any way I can trigger a page to be fragment cached without having someone to load the page the first time? I am planning to use cron schedule, this is because my cron scheduler updates the database and that's when I want to force the fragment cache to happen. Thanks. ...

document.observe('dom:loaded', function() {

Is there a way to have this prototype js trigger only when dom is changed and not loaded? ...

Rails ActiveRecord relationships - has many and belongs to associations

I've created 3 models: Article: contains an article Tag: contains tags ArticleTag: meant for associating a many-to-one tags to article relationship. It contains a tag_id and an article_id. The problem I'm having is I'm fairly new to the active record technology and I don't understand the proper way to define everything. Currently, wh...

modifying Rails load paths in the Rails::Configuration block

I'm trying to figure out how to have Rails NOT load the root models and controllers at app/models and app/controllers at boot. I've tried setting config.load_paths (with config being the Rails::Configuration instance) to both an empty array and nil, but those paths still show up within $LOAD_PATH. Am I missing something here, or is wha...