ruby

How to use paperclip with a file already on my server?

For the record, I'm working on legacy code and I'm trying to plug a new feature without breaking everything. Right now I have a bunch of files on my server as such: myapp/public/temp/myfile.doc The thing is that I want to create a Docfile object from these files in a controller action. Here is the trimmed down Docfile class: class ...

Import ooembed json data with ruby

i want use oohembed for get informations of some links. How can i retreive json data from a link: http://oohembed.com/oohembed/?url=http://www.youtube.com/watch?v=iWhmOPJXpSw&feature=subtivity like { "title": "Aquarium", "html": "", "author_name": "passmorelab", "height": 344, "thumbnail_width": 120, "width": 425, "version": "1....

Rails and I18n: localized templates vs localized string

As you probably know, starting from Rails 2.2, Rails is shipped with a simple localization and internationalization backend. By default, you can store the strings you need to translate in the localization files within the config folder. config/locales/en.yml config/locales/it.yml But Rails provides the ability to localize templates a...

learning http and cgi

I just learned ruby, and already have some html/javascript/css background. When i learn rails i found that there's just too much magic. I want to use ruby to create a dynamic website from scratch - just for learning all the underlying stuff. So is there any book or article well suited for me to getting started with? thanks in advance! so...

Where can I find an actively developed lint tool for Ruby?

Most of the code I write is in Ruby, and every once in a while, I make some typo ( which only gets caught after a while ). This can suck when you have your scripts do some long running tasks, and you return to them only to find out you had a typo. Is there an actively developed lint tool for Ruby that could help me overcome this? Would ...

Why is (python|ruby) interpreted?

What are the technical reasons why languages like Python and Ruby are interpreted (out of the box) instead of compiled? It seems to me like it should not be too hard for people knowledgeable in this domain to make these languages not be interpreted like they are today, and we would see significant performance gains. So certainly I am mis...

Rails routes - index page for subdomain and standard url

Hi, I am using the account_location plugin in my rails app and have the following route map.root :controller => "dashboard", :action => 'index' This route match's on both subdomain.domain.com and www.domain.com How can I set it up so these two domains match different routes? Thanks, Andy ...

How to get name of the test program along with dots while running ruby test

When I run my tests using rake I see dots as the tests are progressing. What I want is the name of the test program before the dots. I am getting some warnings but am not sure which test is throwing the warning. Getting the test name will help me immensely. ...

routing issue, rails generates wrong url.

First of all, Happy Thanksgiving. So my issue is with my routes, I'm not clear on why id param actually contains the entire object. Rails gives me this error: user_url failed to generate from {:action=>"show", :controller=>"users", :id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "[email protected]", crypted_password: ni...

Is there a command line framework for ruby?

So, there are web frameworks, there are GUI frameworks, I was just wondering if there was a console/command line framework for ruby? Specifically, I would like to be able to: Have a particular view wherein I could tab to different input segments. Exactly like you can do with forms on a web page. I would like the usual console shortcut...

check if url is valid ruby

How can i check if a variable is a valid url? e.g. http://hello.it ok http:||bra.ziz, no and if this is a valid url how can i check if this is relative to a image file? thanks ...

Ruby/Rails: converting a Date to a UNIX timestamp

How would I get a UNIX timestamp (number of seconds since 1970 GMT) from a Date object in a Rails app? I know Time#to_i returns a timestamp, but doing Date#to_time and then getting the timestamp results in something that's off by about a month (not sure why...). Any help is appreciated, thanks! Edit: OK, I think I figured it out- I w...

(ruby) ruby sockets: how to create a POST request?

How does one create a POST request using TCPSocket in Ruby? Is there a special format to making a post? I have the following but I get a parse error (it's for a rails server): require 'socket' s = TCPSocket.open("localhost", 3000) s.puts("POST /<controller>/<action> HTTP/1.1") s.puts("Host: localhost:3000") s.puts("Content-Type: applic...

ruby script memory % consumption keeps going up...any way to prevent this ?

as i run my ruby script, which is an very long series of loop. for each loop, some random html file is parsed via nokogiri. top reveals that memory consumption % is incrementing via 0.1 along with cpu usage every few seconds. eventually the ruby script crashes due to "not enough memory" UPDATED to latest: def extract(newdoc, newarra...

preserving visibility when doing an alias_method_chain on attr_accessor in Ruby 1.9

I'm trying to port a library from ruby 1.8. I didn't write the library. I can change the API if absolutely necessary, but it does have a fair number of users I would prefer not to inconvenience. Here's the problem simplified: require 'rubygems' require 'activesupport' class Foo private def self.attr_accessor_with_magic(*attrs) ...

rake db:migrate gives a uninitialized class variable @@configuration in Rails error

uninitialized class variable @@configuration in Rails /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:19:in `configuration' /usr/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.2/lib/factory_girl.rb:24 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' This is the initial part of the envir...

(ruby) help matching my regular expression

I am trying to match the value of the following HTML snippet: <input name="example" type="hidden" value="matchTextHere" /> with the following: x = response.match(/<input name="example" type="hidden" value="^.+$" \/>/)[0] why is this not working? it doesn't match 'matchTextHere' edit: when i use: x = response.match(/<input name="...

Why Cucumber hook methods aren't lowercase?

Hi, Cucumber has a few different hook methods like Before, After or AfterStep. I was wondering - why doesn't these method names follow Ruby's naming conventions to write method names all lowercase? Thanks. ...

(ruby) Broken pipe (Errno::EPIPE)

i have a Broken pipe (Errno::EPIPE) error popping up and i don't understand what it is or how to fix it. the full error is: example.rb:19:in `write': Broken pipe (Errno::EPIPE) from example.rb:19:in `print' from example.rb:19 line 19 of my code is: vari.print("x=" + my_val + "&y=1&z=Add+Num\r\n") ...

conditional chaining in ruby

I have read this question, but I couldn't create a full example: class Some def method_a puts "a" end def method_b puts "b" end def method_c puts "c" end end some = Some.new a = true b = true c = true l = [] l << :method_a if a l << :method_b if b l << :method_c if c l.inject(some) { |obj, method| obj.sen...