ruby

Writing a spec for helper with Ruby on Rails and RSpec

I have been writing specs for controllers and models, but I have never written a helper spec. I have no idea where I start. I have the following snippet in application_helper.rb def title(page_title) content_for(:title) { page_title } end How should I write a helper spec on the code? Also if there's any open-source Rails app...

Generate n unique random integers in ruby / rails

Im trying to generate n unique random numbers between 1 and max I tried the following code but doesn't work (returns repeated numbers) r = [ ] n.times { v = rand(max) while r.include? v ; r << v} Whats wrong with it? Thanks added: max is thousands n is 10 ...

Ruby Console Help with a One-to-Many Association

Hello I've set up a One-to-Many Association between "orders" and "users". I'm wondering how to have console just return an array containing ID's rather than a full array of data: user = User.find_by_login("Lesa") user.orders => [#, #] user.orders.id NoMethodError: undefined method `order' for #<User:0x...

Decreasing font size in rails

Im trying to achieve the following effect in rails: If the text is bigger than x characters then make it smaller, the next x characters smaller, the next character smaller, ad infinitum for example x = 7 would output the following html Lorem i<small>psum do<small>lor sit<small> amet, <small>consecte <small>tur adip<small>isicing</smal...

How do I install Ruby Shoes?

A lot of information seems stale since _why took his toys and went home, yet I would love to use it as a educational tool for my family. Thanks. ...

Recommended two-way encryption gems for Ruby?

Hi all, I'm in need of a two-way encryption solution for Ruby, such as Blowfish, Rijndael (AES) or other. The problem, however, is that I can't find an appropriate gem for it. I would like for the library to support several different encryption algorithms so I can compare the performance of each for optimal integration i my application....

Digital signature verification with OpenSSL

How can I verify CMS/PKCS #7 messages using OpenSSL in Ruby? PKCS #7 message is used as a digital signature for user messages, so I need to sign a new user message and verify the incoming one. I haven't found anything helpfull in documentation and google. I have found few code samples for signing, but nothing for verifying: signed = Ope...

Ruby net-ssh: How to authenticate with pubkey using a gateway

Hello, I am trying to run a script in several machines I have at work, to gather some information about them, such as which OS they're running, what services run on them, some configurations, etc. I have a machine on which I log before ssh-ing to any of the other machines, because of the public key setup it has. From there, I can ssh in...

media conversion library

I am building a mobile website were users can upload/download videos and am looking for a library that can convert the media files from mpeg, 3gp, mov depending on what the user wants to download. thanks in advance. ...

How to store data from session to DB in RoR?

I have a shopping Cart that contains many cart item and price or the order. It remember the users choose in the cart, but does not store into database yet. What should I do to store these records. Cart have many cart item. One cart item contain the number of product, and the product obj. ...

Why I can't loop back the information from db in RoR?

I have a table called "order" which has many "order_items" , each "order_items" is belongs_to "order" and "product". In the db, I have one record in order. the record is like this: orders table: id = 1 name= customer and the order_items table is like this: id=1 product_id=233 order_id =1 id=2 product_id=454 order_id =1 I am trying ...

Processing large XML file with libxml-ruby chunk by chunk

I'd like to read a large XML file that contains over a million small bibliographic records (like <article>...</article>) using libxml in Ruby. I have tried the Reader class in combination with the expand method to read record by record but I am not sure this is the right approach since my code eats up memory. Hence, I'm looking for a rec...

Sending emails from Ruby on rails

Hi, I'm still trying to make this work. Previously, ever since I tried to send an email I used to see a "Email sent" log in the Output window, but after I followed some steps on the web, setting up a smtp_tls.rb file at initializers folder, everything went wrong. Now I don't even see that "email sent" log, and once I delete that file I...

Ruby on Rails: Observers and flash[:notice] messages?

I'm trying send flash messages and welcome notices to users if it's their first time commenting; basically, something like this: class CommentObserver < ActiveRecord::Observer def after_save(comment) if comment.user.new? Mailer.deliver_welcome_package(comment) flash[:notice] = "Welcome! We just delivered a we...

System for organizing multi-file Ruby programs?

Is there a standard or conventional system for organizing multi-file Ruby programs? I have embarked on my first large "project" in Ruby, a search program which is logically organized into multiple files and directories. I've outlined below my potential structure: The main file. This file implements the search class and general searchin...

Counting days excluding weekends

I'm creating a library-style system in Ruby on Rails, and I'm trying to come up with a way to calculate the overdue days while excluding weekends when a borrowed item is returned. Right now I'm just calculating "dayslate" as the difference between the due date and the date the item was actually returned, but I want to exclude weekends, ...

Why is this displaying weird characters on the console?

Take this text for example: the three umlauts are ä, ö, and ü.. Let's assume they are in a text file, which I'm reading like this: data = File.read("umlauts.txt") Now, if I try to output them, I get this: the three umlauts are Σ, ÷, and ⁿ. If I write it to a file, they get outputted correctly. How can I make them show up properly...

How to make block local variables the default in ruby 1.9 ?

Hi, Ruby 1.9 gives the ability to define variables that are just local to a block and do not close over variables of the same name in an outer scope: x = 10 proc { |;x| x = 20 }.call x #=> 10 I would like to have this behaviour as default for some blocks i define - without having to use the |;x, y, z| syntax (note the semicolon)....

RadRails (Eclipse plug-in) not recognizing 1.9.1 ruby features.

I installed RadRails as a plugin to eclipse, and I set the interpreter to C:\ruby, the location of my ruby installation. I've also installed RubyGems 1.3.5 via the ruby setup.rb script. When I run the following, however, I get syntax errors in eclipse, although running works. test = { raw: '1', symbols: '2' } p test Furthermor...

extracting content of content attribute in meta tag of a website given a specified value for the name attribute with nokogiri in ruby?

My first question here, would be awesome to find an answer. I am new to using nokogiri. Here is my problem. I have something like this in the HTML head on a target site (here a techcrunch post): <meta content="During my time at TechCrunch I've seen thousands of startups and written about hundreds of them. I sure as hell don't know all ...