So I think I have a bunch of rubies scattered around here. I want to install rails 3 and watch the railscast online and the person uses rvm to manage ruby versions. I went to install rvm and followed the instruction. I got to the point where I need to do
rvm install 1.9.2
EDIT: and I did
rvm 1.9.2
However after the installation, I ...
Hi all,
I've got a "word" model in my rails app. In the index action of my words controller, I grab a set of words from my database and look up their definitions.
I do not store definitions in my database and do not wish to store them there.
However, I would like the controller to add the definition for each word to the word object bef...
Hi,
I have to implement a fairly database intensive task periodically. I am using rails for the application to which this task is related and thus for the sake of easiness and uniqueness in approach I want to know how can I best implement cron job with rails. I am aware that rake is one solution, but am totally unaware of how to use it....
I am writing a Rails helper method that will add wrapper html to captured content blocks and replace content_for method, such as
- content_for :header do
//haml code
..would become
- content :header do
//haml code
In order to do this I am using Haml and Ruby blocks. This is what it looks like
def content(name,&block)
content_fo...
Hi,
I'm using to_json, and including associations.
However, the resulting json object includes all of the methods for the associated objects, even when I ask it to exclude methods.
I've tried these ways of doing it:
render :json => @entries.to_json(:include => {:labels => {:only => [:label_id, :name], :methods => []}})
render :json =...
I have a large csv. I want to delete the first line of the file. How is this done? I don't want to copy every line into an array and rewrite them for the previous index and delete the first. There must be a better way.
thank you
...
I've swapped out Webrat for Capybara on a new Rails 3 project. I ran through Tim Riley's great post on it here ( http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ), and also cloned his repository, executed the example cucumber feature, and saw the browser window fire open. So the whole Cucumber, Capybara, ...
in php possible to made this:
<input type="text" value=" <?php echo "Hello world"; ?> ">
It's possible to embed ruby in html like that with or without Rails?
...
Let's assume that we need to define a common class for trees (or some other objects we need to have in order to solve a problem). Since our class structure can be quite complex, I prefer to define class methods after its definition. Our common class BaseTree and one of our specific classes Tree are
class BaseTree
class BaseNode; end
...
You can initialize a db attribute to a default value in the following two ways -
Configure your db to assign a default value to that attribute
Use Ruby's initialize method to assign it a value during Object creation (using something like ActiveRecord to talk to your db)
Is there a reason to prefer one of the above methods over anothe...
class C
end
var = "I am a local var outside"
C.class_eval do
def self.a_class_method
puts var
end
# I know, this is not correct, because the 'def' created a new scope;
# I am asking a solution to make it;
# I also know that use 'define_method' can create a instance method without creating a new scope.
# but my...
I'm new to Ruby - I'm having troubles on every step...
Imagine a Ruby script main.rb and a lot of unknown script files script1.rb ... scriptN.rb.
Each scriptX.rb contains unique module with one procedure needs to be executed:
Module X
def some_procedure(i)
puts "{#i} Module X procedure executed successfully!"
end
end
...
Is there a way to know whether or not a method has been overridden by a subclass programmatically? Something that works like this:
class BaseModel
def create
puts "superclass"
end
end
class SomeModel < BaseModel
def create
puts "subclass"
end
end
puts SomeModel.overridden_instance_methods #=> [:create]
Any ideas?
...
How would you list out the modules that have been included in a specific class in a class hierarchy in Ruby? Something like this:
module SomeModule
end
class ParentModel < Object
include SomeModule
end
class ChildModel < ParentModel
end
p ChildModel.included_modules #=> [SomeModule]
p ChildModel.included_modules(false) #=> []
Li...
This is mostly of a design pattern question. I have one type of model that I'm going to get the data to create them from multiple sources. So for example one record my be created from an API where another is created via screen scraping with Nokogiri.
My issue lies in how best to abstract out these different data sources. Right now I...
I have Exam controller.
In routes.rb there is "resources :exams"
In controller there are REST-like generated methods.
I want to add my own method there:
def search
@exams = Exam.where("name like ?", params[:q])
end
In view file:
<%= form_tag(search_path, :method => "post") do %>
<%= label_tag(:q, "Szukaj: ") %>
<%= text_fie...
I came across this great comparison chart between Python & Ruby.
I'm looking for a programming language that is truly a blend between Python and Ruby (with a slight lean towards Python).
I really like in Ruby that everything is an object (unlike Python). However, I really like in Python that things are immutable, so that code maintenan...
What's the best way to parse a css file, and get a list of all the css (using @imports), and the images that are referenced as background-images etc? Is there any parser for css available in ruby??
...
Hello, coming from my experience with nHibernate, I wonder how one maps (n)hibernate's component classes in ActiveRecord
class Person < ActiveRecord::Base
#somehow get a :name attribute here
end
class Name
@fist_name
@last_name
end
how can this be done with one table only (so this is no 1:1, but i want to have a :name_first_na...
How do I make ruby 1.9 the default version to use instead of the 1.8.x that is by default installed on os x?
Thanks.
...