I created a file so I can share a method amongst many models in lib/foo/bar_woo.rb. Inside of bar_woo.rb I defined the following:
module BarWoo
def hello
puts "hello"
end
end
Then in my model I'm doing something like:
def MyModel < ActiveRecord::Base
include Foo::BarWoo
def some_method
Foo::BarWoo.hello
...
I am trying to build a CMS using ERB. Is there a way you can give ERB code read-only access to your models? For instance, I want to be able to load any information on my models (Model.all, Model.find_by_slug, Model.find_by_name, Model.other_model.name, etc...), but I don't want to be able to change this data. Can you disable ERB from ...
eg:
class Base
def self.inherited(subclass)
puts "New subclass: #{subclass}"
path_of_subclass = ????
end
end
Then in another file/class, it extends Base.
class X < Base
....
end
How would I get the path to the rb file of that subclass from the super class.
...
I am using Ruby/WATIR/AutoIt to automate a task via Task Scheduler which runs fine as long as I am logged in, but as soon as my account is locked (mandated 10 minute screen lock) or I logout the script stops functioning. When I log back in, it is sitting at the part where AutoIt is supposed to handle a file download dialogue by clicking...
I found some similar problems here on SO, but none seem to match my case (sorry if I overlooked). Here's my problem: I installed oauth-plugin gem to ruby gems dir, but trying to use it in rails app tells me that it's not being found. Here's the output of relevant commands:
Instalation
% s gem install oauth-plugin
Successfully installed...
In rails guides it's described like this: "Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :dependent => :delete_all."
Right, cool. But what's the difference between being destroyed and being deleted?
I tried both and it seems to do the same thing.
...
Could somebody please explain why the variable named foo remains true in the code below, even though it's set to false when the method is called? And why the symbol version behaves as expected?
def test(options = {})
foo = options[:foo] || true
bar = options[:bar] || :true
puts "foo is #{foo}, bar is #{bar}"
end
>> test(:foo => f...
Hi,
I'm trying to parse web pages but I sometimes get 404 errors. Here's the code I use to get the web page:
result = Net::HTTP::get URI.parse(URI.escape(url))
How do I test if result is a 404 error code?
Thank you,
Kevin
...
I have a test using Cucumber, capybara and selenium driver. This test should go to a form and submit it. The normal text would be
Scenario: Fill form
Given I am on the Form page
When I fill in "field1" with "value1"
And I fill in "field2" with "value2"
And I press "OK"
Then I should see "Form submited"
The probl...
I'm trying to mock a class method with rspec:
lib/db.rb
class Db
def self.list(options)
Db::Payload.list(options)
end
end
lib/db/payload.rb
class Db::Payload
def self.list(options={})
end
end
In my spec, I'm trying to setup the expectation Db::Payload.list will be called when I call Db.list:
require 'db/payload'
d...
Hi,
I'm working on a console ruby application (not rails!) I will be installing this application on several machines. I was wondering if there is a way i can build it so i dont have to install the gems i'm using for the app on each machine. I'd like to be able to just copy the directory to each machine and run it. Ideally, i'd like...
I've got a template for a partial that I'd like to use and I'm wondering if it's possible to just render the thing without needing to send a mock request to a controller. I'm never going to need to render this to an AJAX call, so it seems silly to set up a controller and action, not to mention the security issues with making a private pa...
Simple question: How to install FxRuby on windows.
I have installed ruby 1.9 using one click installer from http://rubyinstaller.org/
...
I would like to list all posts that are connected with some specific category and classroom.
I have:
class Post < ActiveRecord::Base
has_many :category_posts
has_many :categories, :through => :category_posts
has_many :classroom_posts
has_many :classrooms, :through => :classroom_posts
end
class Category < ActiveRecord::Base
h...
I currently have a Postgres DB filled with approx. 300.000 data-sets of moving vehicles all over the world. My very frequently repeated query is: Give me all vehicles in a 5/10/20mile radius. Currently I spend around 600 to 1200 ms in the DB to prepare the set of located vehicle-objects.
I am looking to vastly improve this time by ideal...
I am checking to see if the last character in a directory path is a '/'. How do you get ruby to treat the specific index of a string as a character rather than the associated ASCII code?
For example the following always returns false:
dir[dir.length - 1] == '/'
This is because dir[dir.length - 1] returns the ASCII code 47 (rather ...
I'm writing a small ruby daemon that I am hoping will do the following:
Check if a specific directory has files (in this case, .yml files)
If so, take the first file (numerically sorted preferrably), and parse into a hash
Do a 'yield', with this hash as the argument
What I have right now is like:
loop do
get_next_in_queue { |s| ...
Generally which is better to use?:
case n
when 'foo'
result = 'bar'
when 'peanut butter'
result = 'jelly'
when 'stack'
result = 'overflow'
return result
or
map = {'foo' => 'bar', 'peanut butter' => 'jelly', 'stack' => 'overflow'}
return map[n]
More specifically, when should I use case-statements and when should I simply use a ha...
It is said that when we have a class Point and knows how to perform point * 3 like the following:
class Point
def initialize(x,y)
@x, @y = x, y
end
def *(c)
Point.new(@x * c, @y * c)
end
end
point = Point.new(1,2)
p point
p point * 3
Output:
#<Point:0x336094 @x=1, @y=2>
#<Point:0x335fa4 @x=3, @y=6>
but then,
3...
I want the /admin route on my rails app to be protected by using .htaccess password files - is this possible?
...