ruby

Prawn html formatting

I have some simple lists and bold/italic text to format with prawn. How do I get prawn to pay attention to the html tags instead of just displaying them explicitly. If prawn can't do this, what are my other options? ...

How to tell Builder to not to escape values

ruby-1.8.7-p249 > xml = Builder::XmlMarkup.new => <inspect/> ruby-1.8.7-p249 > xml.foo '<b>wow</b>' => "<inspect/><foo>&lt;b&gt;wow&lt;/b&gt;</foo>" ruby-1.8.7-p249 > Builder is escaping the content and is converting the b tag into an escaped value. How do I tell Builder to not escape it? I am using Ruby 1.8.7. ...

How to build a builder dynamically with escaped values

Now I know how to build xml without escaping values. http://stackoverflow.com/questions/2693036/how-to-tell-bulider-to-not-to-escape-values However I need to build tags dynamically. Desired result <bank_info>Chase</bank_info> What I have is attr = 'bank_info' builder = Builder::XmlMarkup.new builder.attr { |x| x << 'bank_info' } #...

Generating PDF's via Delayed Job while maintaing a RESTful pattern.

Hi, currently I am running a Rails app on Heroku, and everything is working great with exception of generating PDF documents that sometimes contain thousands of records. Heroku has a built-in timeout of 30 seconds, so if the request takes more than 30 seconds, it's abandoned. That's fine, since they offer delayed_job support built-in. ...

How do I require a specific version of a ruby gem?

Specifically, the ruby-oci8 gem. I have both 1.0.7 and 2.0.4 installed. I want 1.0.7. I can just require oci8, but I don't get the version I want. irb(main):001:0> require 'oci8' => true irb(main):002:0> OCI8::VERSION => "2.0.4" I can require using the full path to the file, which works, but is not going to be portable: irb(main):...

Ruby is already using the class name of my model

I'm making a forum application with various levels of authorization, one of which is a Monitor. I am doing this by extending my User class, and I plan on fine tuning this with "-ship" classes (e.g. administratorship, authorship, moderatorship, etc.). Apparently the Monitor class is part of ruby mixin. How do I keep my resource name wi...

How can I use Ruby to check if a domain exists?

Something along the lines of: def domain_exists?(domain) # perform check # return true|false end puts "valid!" if domain_exists?("example.com") ...

Best way to handle multiple tables to replace one big table in Rails? (e.g. 'todo_items1', 'todo_items2', etc., instead of just 'todo_items')?

Update: Originally, this post was using Books as the example entity, with Books1, Books2, etc. being the separated table. I think this was a bit confusing, so I've changed the example entity to be "private todo_items created by a particular user." This kind of makes Horace and Ryan's original comments seem a bit ...

Rails: convert UTC DateTime to another time zone

In Ruby/Rails, how do I convert a UTC DateTime to another time zone? ...

Searching in Ruby on Rails - How do I search on each word entered and not the exact string?

I have built a blog application w/ ruby on rails and I am trying to implement a search feature. The blog application allows for users to tag posts. The tags are created in their own table and belong_to :post. When a tag is created, so is a record in the tag table where the name of the tag is tag_name and associated by post_id. Tags are s...

nokogiri: wrap <tbody> around <table>'s child

how can i do this ? i need to place tbody after table tags, basically to emulate Firefox's behavior. i done this: nodes = @doc.css "table > *" wrapper = nodes.wrap("<tbody></tbody>") Thanks. ...

How do I use Ruby metaprogramming to refactor this common code?

I inherited a project with a lot of badly-written Rake tasks that I need to clean up a bit. Because the Rakefiles are enormous and often prone to bizarre nonsensical dependencies, I'm simplifying and isolating things a bit by refactoring everything to classes. Specifically, that pattern is the following: namespace :foobar do desc "Fr...

ruby-regex: how to match for "/table[number]" ?

i want to match for all "/table[number]" so strings like "/table[1]" and "/table" are matched. ...

What are :+ and &+ in ruby?

I've seen these several times but I can't figure out how to use them. The pickaxe says that these are special shortcuts but I wasn't able to find the syntactical description. I've seen them in such contexts: [1,2,3].inject(:+) to calculate sum for example. ...

Simulating a missing gem in Ruby unit tests

Is there any way to simulate the absence of a gem for certain unit tests, short of actually uninstalling and then reinstalling the gem during testing? I am writing a command line utility, and want to make sure that my tests cover cases where a user may not have all of the gems that I support. For instance, I am using fsevents — a Leopar...

Is there a way to undo Mocha stubbing of any_instance?

Within my controller specs I am stubbing out valid? for some routing tests, (based on Ryan Bates nifty_scaffold) as follows :- it "create action should render new template when model is invalid" do Company.any_instance.stubs(:valid?).returns(false) post :create response.should render_template(:new) end This is fine when I test t...

Request for comments: Ruby script that counts the length of a MySQL table name

Hi, I'm new at ruby and I would like to ask you guys if there's something that could improve my Ruby code. Here's my script: #!/usr/bin/ruby -w require 'mysql' dbh = Mysql.real_connect('localhost', 'db_user', 'password', 'db_table') tables = dbh.query('show tables') tables.each do |table| puts "#{table}" + " (" + "#{table}".length...

osx rvm ruby 1.8.7 nokogiri 1.4.1 - ERROR: Failed to build gem native extension.

I'm stuck with this problem. cat ~/.rvm/gems/ruby-1.8.7-p249/gems/nokogiri-1.4.1/ext/nokogiri/mkmf.log Gives this errors (clipped) conftest.c:3: error: 'xmlParseDoc' undeclared (first use in this function) conftest.c:3: error: (Each undeclared identifier is reported only once conftest.c:3: error: for each function it appears in.) F...

convert jruby 1.8 string to windows encoding?

Hey, I want to export some data from my jruby on rails webapp to excel, so I create a csv string and send it as a download to the client using send_data(text, :filename => "file.csv", :type => "text/csv; charset=CP1252", :encoding => "CP1252") The file seems to be in UTF-8 which Excel cannot read correctly. I googled the problem and f...

Read from a file into an array and stop if a ":" is found in ruby

Hi! How can I in Ruby read a string from a file into an array and only read and save in the array until I get a certain marker such as ":" and stop reading? Any help would be much appreciated =) For example: 10.199.198.10:111 test/testing/testing (EST-08532522) 10.199.198.12:111 test/testing/testing (EST-08532522) 10.199.198.13:11...