This is a large commit. But I want you to concentrate on this change block. http://github.com/rails/rails/commit/d916c62cfc7c59ab6411407a05b946d3dd7535e9#L2L1304
Even without understanding the full context of the code I am not able to think of a scenario where I would use
include Module.new {
class_eval <<-RUBY
def foo
pu...
I'm trying to obfuscate all the ids that leave the server, i.e., ids appearing in URLs and in the HTML output.
I've written a simple Base62 lib that has the methods encode and decode. Defining—or better—overwriting the id method of an ActiveRecord to return the encoded version of the id and adjusting the controller to load the resource ...
I have two models Ticket and TicketComment, the TicketComment is a child of Ticket.
ticket.rb
class Ticket < ActiveRecord::Base
has_many :ticket_comments, :dependent => :destroy, :order => 'created_at DESC'
# allow the ticket comments to be created from within a ticket form
accepts_nested_attributes_for :ticket_comments, :re...
I'm trying to load up rails in the test environment using a ruby script. I've tried googling a bit and found this recommendation:
require "../../config/environment"
ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'test'
This seems to load up my environment alright, but my development database is still being used. Am I doing somet...
I recently switched my database from MySQL to PostGres. I also use GeoKit. When I started my app up with the new database already seeded, I get the following error:
PGError: ERROR: function radians(character varying) does not exist
LINE 1: ...COS(0.661045389762993)*COS(-2.12957994527573)*COS(RADIANS(ti...
...
I have @contacts_added defined as follows:
@contacts_added = Contact.all(:conditions => ["date_entered >?", 5.days.ago.to_date])
Each contact belongs_to a Company.
I want to be able the count the number of distinct Companies that @contacts_added belong to. contacts_added will have many contacts that belong to a single company, acces...
I would like to make two drop downs. a start time, and an end time. Specifically, I only need months. I would like to, for example, choose January, and then March, and then have the database read that it is the these two months plus February.
Is there any out of the box migration that could work?
I'm guessing..
script/generate migrat...
In the _form for creating a new Contact, I want to be able to create a drop-down which allows the User to select the Campaign the Contact will belong to.
In the controller, I created a collection called @campaigns.
And I tried to use the following but not getting it to work:
<p>
<%= f.label :campaign_id %><br />
<%= f.collec...
ok here's some code:
prompt>rails my_app
prompt>cd my_app
prompt>script/generate scaffold service_type title:string time_allotment:integer
prompt>rake db:migrate
then edit these files to look like this:
#routes.rb:
ActionController::Routing::Routes.draw do |map|
map.resources :services, :controller => :service_types
map.connect '...
I have an app that has Basecamp-style subdomains, that is, I have Projects, Users, Apples and Oranges. The Users, Apples and Oranges are all keyed to a Project and only exist in the http://project.myapp.com. I added a project_id to Users, Apples and Oranges and everything works, except of course that the ids of those three objects incr...
So ive got a ActionMailer mailer
class ReportMailer < ActionMailer::Base
def notify_doctor_of_updated_document(document)
recipients document.user.email_id
from "(removed for privacy)"
subject "Document #{document.document_number} has been updated and saved as #{document.status}"
sent_on Time.now
bod...
I am working on a survey application in ruby on rails and on the results page I want to let users filter the answers by a bunch of demographic questions I asked at the start of the survey.
For example I asked users what their gender and career was. So I was thinking of having dropdowns for gender and career. Both dropdowns would defau...
I want to make a post request to a different controller inside my functional test which is intended for a particular controller. However the post method in ActiveController class just takes the method to be called, it doesn't take the controller name to be called. Any ideas how to invoke a different controller?
...
I want to make a simple examing application on RoR 2.3.
The problem area is to make an exam_session in a one form with only one submit action. For the exam session there are selected some number of questions from the question pool in random order. For these questions there are selected some number of alternatives (to check is this a sing...
This is probably pretty simple, but here:
Say I've got two models, Thing and Tag
class Thing < ActiveRecord::Base
has_and_belongs_to_many :tags
end
class Tag < ActiveRecord::Base
has_and_belongs_to_many :things
end
And I have an instance of each. I want to link them. Can I do something like:
@thing = Thing.find(1)
@tag = Ta...
I have the following code:
class Like < ActiveRecord::Base
belongs_to :site
validates_uniqueness_of :ip_address, :scope => [:site_id]
end
Which limits a person from "liking" a site more than one time based on a remote ip request. Essentially when someone "likes" a site, a record is created in the Likes table and I use a hidden fie...
Hi,
I have my views and layouts split into multiple partials, some of them are static partials i.e, no data from the database being displayed here. Does it make sense to cache these to prevent the erb templating system from generating the html each time or it only makes sense to cache in situations where something needs to be retrieved ...
I am wondering how I can order posts in my PostController#index to display by a column total in a separate table. Here is how I have it set up.
class Post < ActiveRecord::Base
:has_many :votes
end
and
Class Vote < ActiveRecord::Base
:belongs_to :post
end
I user can either vote up or down a particular post. I know there are li...
Hi,
I have a controller index action which returns json output.
render :json => my_array.to_json
What type of caching do I have to use here. Does 'page caching' make sense for this.
Or do I have to do action caching like below
caches_action :index
thanks,
ash
...
Hi I'm using the rails plugin acts-as-taggable-onand I'm trying to find the top 5 most used tags whose names match and partially match a given query.
When I do User.skill_counts.order('count DESC').limit(5).where('name LIKE ?', params[:query])
This return the following error:
ActiveRecord::StatementInvalid: SQLite3::SQLException: amb...