I have an interval let's say (0..3) where next element is +1 unless the last. Then the next is 0. I solved it by the code below. Just wondering if there is anything else outhere :-)
def next(max,current)
if current+1 == max
return 0
else
return current+1
end
end
EDIT
please note that when the code runs I need to be able to ass...
Hi,
I am wondering how I could create a custom data type to use within the rake migration file. Example: if you would be creating a model, inside the migration file you can add columns. It could look like this:
def self.up
create_table :products do |t|
t.column :name, :string
t.timestamps
end
end
I would like...
Hello.
I've been developing my first rails application on my windows computer.
But now i have been setting up a debian server with nginx and passanger.
I've been using Github to keep track of my application and now i am wondering how i can get the Github version of my application to the debian server and put it in production mode?
Anybo...
Hello,
I am getting this exception on the Rufus::Scheduler
ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5 seconds. The max pool size is currently 30; consider increasing it.
I've increased the pool from 10 to 30. And I also monkey patched the method which raises the exception to also call Active...
I'm having an odd probably with rails right now... a class is being defined somewhere, and I can't find it. Grepping for "class ClassName" hasn't managed to locate it, but it's definitely there when I load up the rails console. It's just a vanilla class inheriting from Object with nothing else defined... quite boring. So, what I'd like i...
Hello, I'm trying to use ruby-debug19 with Ruby 1.9.1p376 but am getting the following error:
test.rb:2:in `require': no such file to load -- ruby-debug19 (LoadError) from test.rb:2:in `<main>'
Here's test.rb:
require 'rubygems'
require 'ruby-debug19'
Here's the output of "gem list":
*** LOCAL GEMS ***
ruby-debug19 (0.11.6)
(etc.)...
Users can view a specific entry in my webapp with a URL. /entry/8, for example. If an entry doesn't exist, "Entry not found" gets appended to @messages and I render an error page.
I'd like to show some arbitrary query instead of a blank page, but I can't figure out a good way to keep the error message around to be displayed. There are o...
I have two models, product and order.
Product
- cost
- id
Order
- cost
- product_id
Each time someone places an order, it captures the product_id through a radio button value in the "new order" form.
In the controller when creating the new order it needs to set order.cost to order.product.cost. Logically I thought the code shoul...
My purpose is to install ruby/gnome2 and make it work with ruby1.9 on Ubuntu9.10.
I already have ruby/gnome2 working with ruby1.8, but I need to make it work with ruby1.9. I also have ruby1.9 working. When I run within ruby-gnome2-all-0.19.3:
ruby1.9 extconf.rb
it eventually gives me:
Target libraries: glib, gdkpixbuf, pango, atk, gt...
qichunren@zhaobak:~> gem install hpricot
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8 directory.
Current login user is qichunren, and qichunre user have write permission with .gem dir.I would like to know why gem not install files i...
As I always type I am new to rails and programming in general so go easy. Thanks in advance.
I have successfully followed the initial tutorial from Ryan Bates on how to build a weblog in 15 minutes. If you don't know this tutorial takes you through creating posts and allowing for comments on those post. It even introduces AJAX through ...
Try the following code:
s = '#value#'
puts s.gsub('#value#', Regexp.escape('*')) # => '\*'
puts s.gsub('#value#', Regexp.escape('+')) # => ''
Wtf? It looks like the char '\+' (returned by Regexp.escape) is completely ignored by gsub. How to fix this?
...
Is it possible to run jRuby and native ruby on the same machine?
For example installing rake or gem under both it find's Matz Ruby extensions /usr/bin/gem or /usr/bin/rake
The MRI gems and jruby gems are mixed up.
Is there any experience in that constellation ?
Thanks erhard
...
Hi All,
i want to send an email to user after he sign-up with code.for ex
http://192.168.1.51:3000/logins/activate/435546dgfd757676657 #link contains in an email
how can i create the above URL in my notifier model.
i know following way
url_for :controller=>'logins', :action=>'activate', :id=>'435546dgfd757676657' , :host=>'http://192...
Using this xslt file found on this blog to pretty print xml using Nokogiri, everything almost works, but to the point where I can't use it for HTML.
First, if a node is empty, it turns it into a self closing node, so:
<textarea></textarea>
gets converted to
<textarea/>
But that messes up the html tree when rendered.
Second, if th...
Hello,
The Ruby framework I am using provides a TcpServer class which, surprisingly, establishes a TcpServer. It has two threads - one monitors with Kernel.select the listener thread and dispatches a on_client_connect(fd) method and the other monitors established connections and dspatches on_client_data(fd).
I want to use the TcpServer...
The inbuilt Base64 library in Ruby is adding some '\n's. I'm unable to find out the reason. For this special example:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'base64'
=> true
irb(main):003:0> str = "1110--ad6ca0b06e1fbeb7e6518a0418a73a6e04a67054"
=> "1110--ad6ca0b06e1fbeb7e6518a0418a73a6e04a67054"
irb(main)...
I'm working on a basic garden logging application which consists of gardens, plants and planted plants. Each user has one or many gardens, plants are master definitions, and a planted plant can be thought of as an instance of a plant in a specific user's garden.
In my routes.rb file I have the following:
map.resources :gardens do |gar...
I noticed that Sinatra does not recognize index.html files in public folder's subdirectories and returns an error when url is pointing to a directory without specifiying the file name.
For example, if user enters a url like "www.mydomain.com/subdiretory/", Sinatra fails to recognize the existence of an index.html file in that directory....
If I run a command like this, using ruby's pty class, how do I kill it if I find a certain input string?
cmd = "appcfg.py update cdn"
PTY.spawn("#{cmd} 2>&1") do | input, output, pid |
begin
input.expect("Email:") do
output.write("#{credentials[:username]}\n")
end
input.expect("Password:") do
output.write("#{cr...