ruby

How do I create a Up/Down voting system like stackoverflow?

Hey guys, I'm making a site in Rails, and I want to add a vote up/down system like here in Stackoverflow. Can anyone suggest how to do it? I do know that I'll enter each vote into the database, but I mean, how do I code the vote buttons? What will I use, can anyone help me. Ajax isn't required but it would be nice. I was going to try t...

ENOENT while creating a UNIX socket in Ruby

I'm trying to create a socket in Ruby using require "socket" w = UNIXSocket.new("socket") and I keep running into No such file or directory - socket (Errno::ENOENT) This looks completely backwards to me, because new() is supposed to create that missing file. What am I missing? ...

Can someone check what's wrong with this code?

I'm sorry for the title nad no idea what to name if, anyone mind changing it for me? Hey guys, I'm not sure if I'm able to do this or not in rails, but I tried it just to see if it'll work or not, hopefully someone understands what I'm trying to do <% @grinders.each do |grinder| %> <div id="main"> <div style="float:left; height:80p...

Ruby Question one line if statement

<%if @item.rigged %>Yes<%else%>No<%end%> I was thinking of something like this? if @item.rigged ? "Yes" : "No" But it dosen't work. Ruby has the ||= but I"m not even sure how to use that thing. ...

How would I break up and extract an array from an array-of-hashes in Ruby on Rails?

for example: [ (id=>1, email=>'[email protected]', name=>'tim'), (id=>2, email=>'[email protected]', name=>'joe'), (id=>3, email=>'[email protected]', name=>'dan') ] How can I extract the email column and put it in its own array? ...

How to get a stack trace object in Ruby?

I need to get a stack trace object in Ruby; not to print it, just to get it to do some recording and dumping for later analysis. Is that possible? How? ...

Hacking ActiveRecord: add global named scope

I am trying to have a pack of very generic named scopes for ActiveRecord models like this one: module Scopes def self.included(base) base.class_eval do named_scope :not_older_than, lambda {|interval| {:conditions => ["#{table_name}.created_at >= ?", interval.ago] } end end end ActiveRecord::Base.send(:inc...

werid, same expression yield different value when excuting two times in irb

irb(main):051:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,"#{$1} ?") => "ts_id > ?" irb(main):052:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,"#{$1} ?") => "ts_id < ?" Can anyone enlighten me? ...

nil values magic

I have faced the plain simple situation, that i can't figure out. I have to deside, whether to show the "more" link, depending of the articles count The code is plain simple @no_more = offset + length >= Article.count @no_more variable equals to nil sometimes. I see in debugger, that offset=0, length=10 and Article.count=12 But the...

regex to remove the webpage part of a url in ruby

I am trying to remove the webpage part of the URL For example, www.example.com/home/index.html to www.example.com/home any help appreciated. Thanks ...

Why JavaScript returned another page, when i set new window.location?

Hello, all. Have one a question. When i, for example, on "page 1" page, i have js in html: <% if session[:download_link_for_pricing] %> Event.observe(window, 'load', function() { if (confirm("Download new Pricing?")) { location.href = "<%= session[:download_link_for_pricing] %>"; }...

Ruby eventmachine error: 'no loop breaker'

I get a slightly heisen error from eventmachine (0.12.10, on OSX 10.6.4): terminate called after throwing an instance of 'std::runtime_error' what(): no loop breaker It only occurs in tests, and only when all tests are run together. Run individually they pass. I spotted the only place in the eventmachine code that mentions the err...

Simple socket program in Ruby

I want to write a simple server socket in Ruby, which, when a client connects to it, prints a message and closes the client connection. I came up with: require 'socket' server = TCPServer.open('localhost',8800) loop { client = server.accept Thread.start do s = client s.puts "Closing the connection. Bye...

RubyGems + Cygwin: POSIX path not found by ruby.exe

I am a Ruby programmer on Windows who trys to switch from Win cmd to Cygwin, but cannot achieve to execute batch files of Ruby gems. I already stuffed any bin directory into the Windows PATH env. variable, including the Ruby bin where the executables are stored. Gems, however, are invoked by ruby.exe itself, which leads to the following...

Ruby strftime: Month without leading zero?

Does Ruby's strftime have a format for the month without a leading zero? I found %e for getting the day without the leading zero, but not having any luck with the month. Ultimately wanting a date formatted like: 9/1/2010 ...

undefined method `id' in simple Ruby Program

I've found one question like this on stackoverflow, but it doesn't answer my question. I'm following along with http://www.ruby-doc.org/docs/ProgrammingRuby/ to learn Ruby, but I'm running into problems with the example code and it's frustrating. person = "Tim" puts person.id puts person.type puts person The error message I'm getting...

Ruby date cutoff in Time.parse()

Ruby's Time.parse() works for dates from Dec 14 1901 up Jan 18 2038 (this appears to be system dependent): # works irb(main):038:0> Time.parse('14-12-1901') => Sat Dec 14 00:00:00 -0600 1901 # doesn't work irb(main):039:0> Time.parse('13-12-1901') ArgumentError: time out of range from /usr/lib/ruby/1.8/time.rb:184:in `local' f...

Ruby Set class: equality of sets.

According to the Ruby Set class's documentation, "== Returns true if two sets are equal. The equality of each couple of elements is defined according to Object#eql?. The essence of this can be demonstrated using Date objects, where sets containing different Date objects but with the same date compare to equal: require 'set' d1 = Date.t...

[rails3] comments not saving post_id

Im running into a small (newbie) problem. I've got 2 models: question & reviews. Reviews schema: question_id, user_id, rating, comments On the 'show' view, i've integrated the following form (formtastic): - semantic_form_for @question.reviews.build do |f| = f.error_messages = f.input :rating = f.input :comments = f...

Bundler and gems on github

So when you have bundler install a gem from github, it doesn't actually get installed, does it? gem list won't list those gems. Which brings me to my conundrum: I'm working on a script that wants to use one of these gems that don't actually get installed. Now what? I could check out the github repo manually and build/install the gem, b...