I'd like to write a simple function to say in hours :
How much time has passed since this has been created?
My attempts are futile.
-time = DateTime.now.hour - (self.created_at.hour)
Does anyone know how to do this in Ruby on Rails?
...
The following example fails
class A
class B
end
end
p Object.const_get 'A' # => A
p Object.const_get 'A::B' # => NameError: wrong constant name A::B
UPDATE
Questions about the topic asked earlier:
Cast between String and Classname
Ruby String#to_class
Get a class by name in Ruby?
The last one gives a nice solution which can...
What are the key differences between Ruby and C?
...
I have a web application written mostly in Java. There are a few users that hope to use ruby to tailor this application to suit their own needs. How would I write an API that allows Ruby developers to interact with my application?
I'm really looking for some direction here - I know it's a broad question..
...
So I just started with Rails and right now looking over HABTM. I am reading the DHH book and I see that he has two models namely article and user. They have HABTM relationships. I am wondering however whether I need to create a separate migration for the articles_users model by myself or will Rails do it for me?
If so, what happen if I ...
Hi
I am using following versions of Ruby and Rails on arch linux
[hardik@sunshine: kandibank ]$ ruby --version
ruby 1.9.1p429 (2010-07-02 revision 28523) [x86_64-linux]
[hardik@sunshine: kandibank ]$ rails --version
Rails 2.3.8
I am using the sqllite database in development mode.
I can store a string having German special character...
@string = "\x16\x03\x01\x00\x91\x01\x00\x00\x8D\x03\x01LI.\e\x8F|\x06\f\xA2Tu\xC8WW\xCF\x87G2O,98\xEC\xADMM H\xB4\x0E-G\x00\x00H\xC0\n\xC0\x14\x00\x88\x00\x87\x009\x008\xC0\x0F\xC0\x05\x00\x84\x005\xC0\a\xC0\t\xC0\x11\xC0\x13\x00E\x00D\x00f\x003\x002\xC0\f\xC0\x0E\xC0\x02\xC0\x04\x00\x96\x00A\x00\x04\x00\x05\x00/\xC0\b\xC0\x12\x00\x16\x0...
Fairly abstract question here, as I don't know quite where to start my own investigations.
I have a C package constructed with CMake that produces librpdb.so; I have a Ruby Gem set up for the same library, which produces rpdb.bundle.
When used in Ruby, I get this:
dyld: lazy symbol binding failed: Symbol not found: _RPDB_RuntimeStor...
Hello, first question, hopefully I don't mess it up :)
A bit of a Ruby on Rails newbie (also Ruby newbie) and have stumbled upon a problem with the intended behavior of the application.
I have a file_column :image in model picture that belongs to model product, which can have many pictures.
The file_column works just fine when used as...
I have a Rails 3 model "D" that belongs to another model, which belongs to another two in turn, like this:
D belongs to C
C belongs to B
B belongs to A
I am using MongoDB/Mongomapper as my ORM.
When I try to instantiate D, I am getting an error:
ruby-1.9.2-preview3 > d = D.new
SystemStackError: stack level too deep
from /Users/peter...
Hi,
I'm using a pre-commit hook for Git that checks the syntax of my files before I can commit them.
In a Rails 3 app (I'm using the new form helper's syntax : <%= form_for @article do |f| %> but I get a syntax error, not when I use the app, but when I check for the syntax through the ruby CLI command or the Textmate's bundle command.
...
I would like this custom step:
Then I should see the link 'foo'
and his opposite:
But I should not see the link 'foo'
In the page I can have something like:
lorem foo bar
or alternatively
lorem <a href=''>foo</a> bar
I need to test when 'foo' is a link and when isn't. Thank you.
...
What have you found as the best sources for jRuby interop syntax with Java? It took me forever yesterday to find something about adding to the classpath and the jruby.org site was not much help. Curious what references others use. Thanks.
...
Is there a way to parse feed's custom elements? Not feed entries', feed's custom elements. I know there is a way to do the same for the entries. Like,
Feedzirra::Feed.add_common_feed_entry_element("wfw:commentRss", :as => :comment_rss)
feed = Feedzirra::Feed.parse(some_atom_xml)
feed.entries.first.comment_rss # => wfw:commentRss is now ...
I have a polymorphic association like this -
class Image < ActiveRecord::Base
has_one :approval, :as => :approvable
end
class Page < ActiveRecord::Base
has_one :approval, :as => :approvable
end
class Site < ActiveRecord::Base
has_one :approval, :as => :approvable
end
class Approval < ActiveRecord::Base
belongs_to :approvable...
Hello everyone,
i want to strip a quote in the following cucumber expression, but i get unknown step error
Then I should see "[\"20257\"]\n"
Cucumber suggested me this :(
Then /^I should see "([^"]*)"(\d+)\\"([^"]*)"$/ do |arg1, arg2, arg3|
pending # express the regexp above with the code you wish you had
end
Any ideas, how to s...
Just tried writing a simple validates_presence_of in my model, and when the errors try to render, it calls this :
Template is missing
Missing template posts/create with {:locale=>[:en, :en], :handlers=>[:builder, :rjs, :erb, :rhtml, :rxml, :haml], :formats=>[:html]} in view paths "/Users/johnsmith/Sites/shwagr/app/views"
Errors don't...
Hi,
I am writing a Ruby on Rails app. which will use a 3rd party to do a webservice call or a rest call or some sort of call. I am not sold on which 3rd party I am going to use so I want to isolate this in some sort of facade.
If I was doing this in .NET, I would isolate this functionality in a service that I inject into the controlle...
In my app I want the time/date to display as Month/Year (e.g. 7/10). The problem is sometimes I get class Date and sometimes class Time so I wind up with the following code in the application controller ...
class Date
def as_month_and_year
self.strftime("%m").to_i.to_s + self.strftime("/%y")
end
end
class Time
def as_month_an...
Thoughout our app we use number_to_currency(value, :precision => 2). However, we now have a requirement whereby the value may need displaying to three or more decimal places, e.g.
0.01 => "0.01"
10 => "10.00"
0.005 => "0.005"
In our current implementation, the third example renders as:
0.005 => "0.01"
What's the best approach ...