Hi all
I have the following model association: a student model and has_many scores.
I need to make a list showing their names and average, min, max scores. So far I am using
student.scores.average(:score) on each student, and I realise that it is doing one sql per student. How can I make the list with one joined sql?
Also how would I...
Hi,
I was trying to run an OpenSource project which requires ferret to be installed. While installing it using gem install ferret, it's giving this error ->
Building native extensions. This
could take a while... ERROR: Error
installing ferret:
ERROR: Failed to build gem native extension.
C:/Ruby/bin/ruby.exe ext...
Basically url escapes a string except uses '+' instead of '%20' for spaces.
...
Hi,
I've a model which use paperclip, in dev env I want to store files on the file system.
In production I want to store them on my s3 account.
How to configure my model to reflet this difference?
Here is my model
class Photo < ActiveRecord::Base
has_attached_file :photo, :styles => { :medium => "200x200>", :thumb => "100x100>" },...
In Rails 2.x you can use validations to make sure you have a unique combined value like this:
validates_uniqueness_of :husband, :scope => :wife
In the corresponding migration it could look like this:
add_index :family, [:husband, :wife], :unique => true
This would make sure the husband/wife combination is unique in the database. No...
So, I'm thinking about applying for Ruby Summer of Code. However, I'm not sure what I want to propose. I was wondering if any of you had any good ideas?
I've been programming in Ruby for about 3 years. I am primarily a web developer, but I do things related to bit torrent, data mining, and databases as well. I have a bit torrent related...
Lets say we have some basic AR model.
class User < ActiveRecord::Base
attr_accessible :firstname, :lastname, :email
end
...
some_helper_method(attrib)
...
def
Now I would like to pass someuser.firstname to helper and I would like to get both the value and the attribute name, for example:
some_helper_method(someuser.firstname)...
If i enter a url directly into the address bar of the browser, i get the following results:
logger.debug ENV['HTTP_REFERER'] // =>
logger.debug request.referrer // => /
So the first one gives me a blank result which is what I expected but the second gives me the root? Is this correct? It seems from the docs (http://api.rubyonrai...
I am using jQuery to make an AJAX call to a ruby method in my controller. The javascript looks something like this:
var latLongJSON =
{
"address": [
{"lat" : 50,
"long" : 50} ]
};
var returnedAddresses;
$.ajax({
type: "GET",
data: latLongJSON,
url: "map/getaddresses",...
Is there any way to create a custom capistrano task for performing other actions on a scm repository?
For instance, I would like to create a task that will checkout a particular folder from my repository and then symlink it into the shared/ directory of the main project on my server.
I know this can be done by creating a task and expli...
I have two models:
class Solution < ActiveRecord::Base
belongs_to :owner, :class_name => "User", :foreign_key => :user_id
end
class User < ActiveRecord::Base
has_many :solutions
end
with the following routing:
map.resources :users, :has_many => :solutions
and here is the SolutionsController:
class SolutionsC...
I have an application layout in my rails app to give a default header/footer for my entire website. I have 1 controller that I dont want this to apply to (a checkout page), and an entire namespace that needs to have a separate default template (the admin interface, which has 10-15 different controllers). What is the easiest way to do t...
Hi i have these classes:
class Core < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
belongs_to :image, :class_name => 'Multimedia', :foreign_key => 'image_id'
end
class Place < ActiveRecord::Base
has_one :core, :as => :resource
end
If i try do launch this:
a = Place.find(5)
a.name ="a"
a.core.i...
Martin Fowler's Runt library is really handy for date/time comparisons, and this code works great in an irb console:
require 'runt'
include Runt
r_start = PDate.month(2010,12)
r_end = PDate.month(2011,12)
range = DateRange.new(r_start,r_end)
o_start = PDate.month(2010,11)
o_end = PDate.month(2012,2)
o_range = DateRange.new(o_start,o_en...
Hallo
rails version 2.3.5
I'm learning rails and I run into a problem.
I'm doing some nesting forms from the railscasts tutorials. I changed the text area into a data field to upload photos and everything is working.
Now i have to display the uploaded pictures and i simply can't do it. I Tried everything I could find on the net but...
In my users controller I have this in a method:
@users = User.paginate :page => params[:page], :per_page => 10,
The results are rendered on users/search. The 2nd page link points to users/search?page=2, but it leads to an unknown action error.
...
Hi
I am trying to figure out the "right" way to do this.
In my application every time I create a new user I want to have specific data loaded into an associated table. The associated table is a different preset lists. So a User has many lists and those lists have many items. Some of those Items I want to be loaded when the User is creat...
I have a file called config.yml in my /config folder of my rails application.
I also have an initializer: config/initializers/load_config.rb with the following code:
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")
I am using the Whenever gem to set up a cron job, and would like to use my APP_CONFIG to call a function li...
How can I make a helper that will tell me how many weeks ago (rounded down) with rails? It could be based of the time_ago_in_words helper however I'd want it to return: "last week" then afterwards just two weeks ago, three weeks ago, etc...
...
I'd like to have an image and a combo box with 2 options: color, and black and white. When the combo box selection changes, I'd like to return the image as black and white and have this done dynamically on the server (so I don't have to store the black and white image on the server).
I was thinking I could point the img tag at a url li...