ruby

Can nokogiri search for "?xml-stylesheet" tags ?

I need to parse for the an xml style sheet <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="/templates/xslt/inspections/disclaimer_en.xsl"?> Using nokogiri I have tried using doc.search("?xml-stylesheet").first['href'] but I get the error `on_error': unexpected '?' after '' (Nokogiri::CSS::SyntaxErro...

Make new document in TextMate with rb-appscript or AppleScript?

How do I make a new document in TextMate using rb-appscript or AppleScript? Here is my rb-appscript: te = app("TextMate") te.launch doc = te.make(:new => :document) But it doesn't work. Here is the error message I get: OSERROR: -10000 MESSAGE: Apple event handler failed. COMMAND: app("/Applications/TextMate.app").make({...

how does one remove <![CDATA[ ]]> tags from around text in XML using Hpricot?

i just want the text out of there with out those tags. Does Hrpicot.XML have any methods for this? ...

Convert Ruby to low level languages?

I have all kind of scripting with Ruby: rails (symfony) ruby (php, bash) rb-appscript (applescript) Is it possible to replace low level languages with Ruby too? I write in Ruby and it converts it to java, c++ or c. Cause People say that when it comes to more performance critical tasks in Ruby, you could extend it with C. But the wor...

How should I make a Javascript and Ruby based order form that sends info and uploaded images to an email address?

I am planning on making an order form that has text fields (to gather submitted text based information like names, emails, messages) link fields (to gather submitted links) upload buttons (to gather images from a user's hard drive) I assume I will be using Javascript and Ruby for this but I have a few questions. how would I activa...

Need help with loops

Hi, I need a loop in this pattern. I need an infinite loop producing number that start with 1. 1,10,11,12..19,100,101,102..199,1000,1001....... ...

sending POST in ruby ?

any good library to send POST headers in ruby ? ...

Benchmarks of scripting languages doing the same task?

This is not a X vs Y question - do not reply as same. Does anyone know where I could find reviews or reports on tasks that people did in two or more high-level scripting languages to see which one was more suited for a certain job? (note that this is different from looking for a language suited for all jobs!) I really want to know which...

MacRuby+IronRuby or JRuby for Desktop Applications?

For Web Applications I use Ruby on Rails. And now it's time to see if I can code Desktop Applications with Ruby. So I wonder which one I should choose. The way I see it is MacRuby+IronRuby vs JRuby. The former lets me have desktop applications for both Mac and Windows while the latter lets be have in both, but only learning one tool. ...

Why is REXML removing elements from the end of the XML object instead of copying?

Hi everyone, We have this method in our Ruby project. It accepts an XML object (which consists of three different "trees") and is supposed to copy X elements from the end. For some reason, what it does is move those elements -- and then the original XML object (which we passed to it) gets cut off. We tried .clone but it doesn't copy th...

What is the difference between "generator" and "scaffolding"?

What stuff does each one do (or, generate?) pardon the pun. ...

What is "respond_to" and "do" and "|format|" in this code? Some help with rails please?

class PostsController < ApplicationController # GET /posts # GET /posts.xml def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @posts } end end ... What exactly is "respond_to" Is it part of rails? What is "do" and"|format|"? Why are there verti...

How do i create a human readable datediff in Rails

I have a timestamp that represents the last time a particular record was viewed. I want to present to the user a display that gives a human readable representation of the difference between that time and now. So it should be something like "Last viewed 38 seconds ago" or "Last viewed 1 hour 15 minutes 10 seconds ago" Is there a qui...

Ruby - why put a module inside a class?

In Ruby, I see that it can be useful to put classes inside modules for namespacing. I also see that it's possible to put moduldes inside classes. But I don't see why you'd do that. Modules are generally mixed into classes, right? So what would be the purpose of defining a module inside a class? (I also notice that Googling "ruby 'modul...

ruby proc issue

Following code works def lab Proc.new { return "foo1" }.call return "foo2" end puts lab #=> foo1 Following does NOT work. Why?. I get LocalJumpError class Foo def self.doit(p) p.call end end p = Proc.new { return 'from block' } a = Foo.doit(p) puts a ...

Ruby iterator practice

Hi guys, I am currently learning Ruby and I am wondering whether you guys can suggest some medium to difficult iterators to implemet? Thanks ...

Testing view helpers in Rails with RSpec

Guys, I need to test the following helper: def display_all_courses @courses = Course.all output = "" for course in @courses do output << content_tag(:li, :id => course.title.gsub(" ", "-").downcase.strip) do concat content_tag(:h1, course.title) concat link_to("Edit", edit_course_path(course)) end end ...

Ruby on Rails 'find' question

I'm currently using: @user = User.find(params[:id]) @posts = Post.find(:all, :conditions => ["user_id = ?", @user.id]) @comments = Comment.find(:all, :conditions => ["user_id = ?", @user.id]) Which identifies the user, and lists all their comments they've made. However, I want to set a local variable for use in the _comment.html.erb ...

How to import Apache access log into MySQL table?

What is the recommended approach to import Apache access log into a MySQL table? I am thinking of a ruby/perl script + a cron job. It'll be great if there is an example or reference. I am not sure how to handle the bookmarking of the last log entry in last import either. Suggestions are welcome. Thanks! ...

Ruby on Rails question

I'm currently using: @user = User.find(params[:id]) @posts = @user.posts @comments = @user.comments To display all my comments with this code in my template: <% @user.comments.each do |p| %> <p>Commented on <%= p.post.user_id %>'s post</p> <p><%= p.body %></p> <% end %> Each post has a 'user_id' column which is the user's ID fo...