Delete all the content from file.
I want to remove the content form the list of files. EDIT : I have list of files. file1 file2 file3 Those file containing bunch of lines ... I want to remove all the lines from each files. ...
I want to remove the content form the list of files. EDIT : I have list of files. file1 file2 file3 Those file containing bunch of lines ... I want to remove all the lines from each files. ...
I seem to have gotten myself turned around while trying to install Rails 3 and haven't been able to figure out what I'm doing wrong. Prior to trying to upgrade I was on 2.3.2 Here's what I have thus far... $ which ruby /usr/local/bin/ruby $ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.8.0] $ which rails /usr/bin/rail...
RSpec allows you to get the current running test method name in a before(:each) block, by doing the following: Spec::Runner.configure do |config| config.before :each do |x| x.method_name # returns 'should be cool' end end This is for a test like: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe '...
$ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.3.0] $ rails s => Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-09-28 13:45:50] INFO WEBrick 1.3.1 [2010-09-28 13:45:50] INFO ruby 1.8.7 (2009-06-08) [universal-dar...
Hello, I am quite new to ruby on rails, but I find it phantastic. Anyway, I am currently building my model-set, so to speak. I have a model Places, generated like this: rails generate scaffold Place name:string description:text type:string Now I want to make a model Route between two places, holding a distance. How can I do that, I o...
I wrote a ruby class that I want to use in other applications that I have. I put it in the same directory c:\apps that I have my other applications in. When I require my class it says that: `require': no such file to load -- Even though the file is in the same directory as the application I am running. I am simply doing a : require 'f...
Say I have 1200 ActiveRecord objects with a created_at attribute, and 100 were created each month for a year. What's the one liner ruby way to iterate through the records and chunk them by month? [record_a, record_b, record_c, ...].group_by(&:month) do |month, records_for_the_month| records_for_the_month.each ... end ... assuming I...
Here's what I'm trying to do. Let's say the user is looking at the foo view for the foo action of the bar controller, and I've got a variable called @userName. bar_controller.rb class BarController def foo @userName = getUserName(); end foo.html.erb Hi mom! I want to create a filed called <%= @userName %>.myExt with the i...
I would like to use rubyzip to archive "zip" an existing file: c:\textfile.txt to textfile.zip I know how to add a stream to a text file: require 'zip/zip' Zip::ZipFile.open("mp.zip", Zip::ZipFile::CREATE) { |zipfile| zipfile.get_output_stream("text.txt") { |f| f.puts "Creating text file" } } but not how to add an ex...
Brief question, beginner's work on Ruby/Rails. Here's my view: <h1>News</h1> <%= @posts.each do |post| %> <h1><%= post.title %></h1> <p><strong>By:</strong> <%= post.name %></p> <p><%= post.content %></p> <p><%= link_to 'Read More', post %> | <%= link_to 'Edit', edit_post_path(post) %> | <%= link_to 'Destroy', post, :confirm => 'A...
I'm writing an implementation of a diffie-hellman key exchange in ruby for a project for one of my university classes. I need to generate large (secure) prime numbers of at least 500 bits length. Any ideas? Should I use the OpenSSL library? If so, what functions would you recommend? ...
I am new to Nokogiri and xpath and I am trying to access all comments in a HTML or XML fragment. The xpath ".//comment()" and "//comment()" works when I am not using the fragment function, but it does not find anything with a fragment. With a tag instead of a comment, it works with the first xpath. By trial and error, I realized that in...
So I'm making a survey app. The users choose a type of form on the backend, and it displays as a certain type on the front end. That's only ideally, of course. What happens now is I can't access the object formtastic is building the form for. How can I say something like "question.kind"? It just makes an error that way. Here's what I hav...
I want to do something similar to this: def creator() return lambda { |arg1, arg2 = nil| puts arg1 if(arg2 != nil) puts arg2 end } end test = creator() test('lol') test('lol', 'rofl') I get a few syntax errors: test.rb:2: syntax error re...
Trying to use Net::SFTP, version 2.05 (appears to be the latest). But it fails even on its own sample code (below, from http://net-ssh.rubyforge.org/sftp/v2/api/index.html). The domain, user and password are the same as I use to log in manually. I will change the paths when I can get that far. Net::SFTP.start('ftp.domain.com', 'user', :...
I need to create an SSLSocket in ruby (1.8+) to talk to an encrypted service. I want to set ssl options on the SSLContext object. (something that eventually calls SSL_CTX_set_options in the underlying openssl library). I am not seeing any obvious way to do this. This is using the OpenSSL::SSL::SSLContext interface. As a point of refere...
I need to clean up various Word 'smart' characters in user input, including but not limited to the following: – EN DASH ‘ LEFT SINGLE QUOTATION MARK ’ RIGHT SINGLE QUOTATION MARK Are there any Ruby functions or libraries for mapping these into their ASCII (near-) equivalents, or do I really need to just do a bunch of...
Hello all. I'm trying to scrape the the Yellow Pages website. Specifically, this link http://www.yellowpages.com/santa-barbara-ca/restaurants. My code works perfectly except for one small problem. Because the "Next" link to go to the next page of restaurants is a relative link, Scrubyt's "next_page" function doesn't work...apparently...
I'm totally new to Ruby but not to programming. All I did was going through try ruby and reading differences from other few languages I know better (mostly PHP and some Python). So I have no idea how Rails differ from Ruby and maybe this is an absurd question. Anyways... I don't want (or am able) to install Ruby on my machine and I'd ...
I have a class Document (in a mongodb collection) and persist various sub classes (like Page < Document). Now I do a Document.all()- how do I generate links to the document's edit action pointing to the right controller (PageController for pages) without being verbose about it? <%= link_to document.title, [:admin, document] %> points ...