ruby

ruby on rails fleximage plugin

How do I display the image in a view? The documentation says: <%= image_tag formatted_photo_path(@photo, :jpg) %> This is not what I want. I just want to display an image on a view I don't care about the url. E.g., Avatar. Do I need to write a path to the directory or is a method already made? /public/images/avatar/id Thank you ...

ActiveRecord Custom Field Method

Lets imagine that I have a custom image upload for a particular record and I add two columns into the model. thumbnail_url thumbnail_path Now lets imagine that I have a form with a :file field which is the uploaded file in multipart form. I would need to somehow have the model pickup the file within the given hash and then issue it ove...

What's a better syntax for comparing one string to multiple other strings?

I am basically looking for a prettier way to write: do_something() if my_string == 'first' | my_string == 'second' | my_string == 'third' Any ideas? ...

Loop from contents of a file in ruby.

Okay, so I am new to Ruby and I have a strong background in bash/ksh/sh. What I am trying to do is use a simple for loop to run a command across several servers. In bash I would do it like: for SERVER in `cat etc/SERVER_LIST` do ssh -q ${SERVER} "ls -l /etc" done etc/SERVER_LIST is just a file that looks like: server1 server2 s...

Must know Ruby on Rails + Ruby plugins

I'm fairly new in the Ruby + Rails scene. Although I have a very strong understanding of design patterns, data structures and algorithms - there's a ton of "must have" plugins that I haven't had a chance to run into yet. There's things for migrations, resource controllers and a myriad of other plugins that make developing for these platf...

How do you think Reddit handles reindexing their posts to keep the accurately in order?

I can't imagine it indexing per vote. It would strain the server innapropriately. I mention this because I'm trying to do something similar on a project of mine, and can't figure out what the best way to index objects after they have been voted on. I am using Sunspot-Solr. ...

Detailed RoR app ... XML w/ MySQL or just MySQL

The project: Imagine a card collector wants to create a database for all his card collections , they collect every type of trading card available. Each trading card has a different set of information (stats) depending on it's type but there could be an infinite number of categories of trading cards. So my questions is, is it better to cr...

Write an atomic operation

Hi, I would like to execute some methods atomicity with Ruby, according to http://en.wikipedia.org/wiki/Atomicity_(database_systems) For instance, if I have: a = 30 b = 75 I would like to be able to do something like: atomic_operation do a += 10 b -= 39 end Is there a native module in Ruby 1.9 that allow such process? If pos...

Multiple instances of a single object in a Rails Array?

G'day guys, trying to build a small invoicing system (that can generate PDF's using prawn), but am having an issue with generating multiples of indivdual items in the array. I have the Invoice class which has_many :items, but when I try to add a multiple of an item to the invoice, it won't actually add that to the invoice and it doesn't ...

How to remove all non - ASCII characters from a string in Ruby

Hi, I seems to be a very simple and much needed method. I need to remove all non ASCII characters from a string. e.g © etc. See the following example. #coding: utf-8 s = " Hello this a mixed string © that I made." puts s.encoding puts s.encode output: UTF-8 Hello this a mixed str ing ┬⌐ that I made. When I feed this to Watir, i...

How to send Mobile Images to Ruby Server using J2ME has a Client Side

In Client Side:J2Me it retrieve the mobile photos and store it in RMS database.. Then send all photo's to Ruby (Server) Script Over Http. In Server Side:RUBY Ruby script Receive that photos and store it in server.. In PHP: I ll give URL="http://localhost:80/upload.php.in J2me(Client side)...It's working Fine.. But now i use Ruby in...

parse Google Image search results without Google AJAX API

Hi, How to get Google Image results URL on Ruby without using Google AJAX API. I tried to get all node with tag and id beginning with ipf* but I got only 11/21 images URL... with these APIs :'open-uri' and 'rubyful_soup' It seems Google has merged HTML (for the 11 first results) and dynamic HTML generated by javascript (for the 10 ot...

Using Webrat to check a list has a specific number of li elements

For a cucumber step, I know that a particular ul element should have 5 children li. How can I assert this with Webrat? I'm guessing there could be something like: Then ".selector" should have n ".another-selector" or maybe Then I should see n ".selector" within ".another.selector" Is there anything like this floating around, or sho...

Is there an elegant way to remove a specific key from a hash and it's sub-hashes in Ruby

Lets say I have a hash which may contain hashes. params: { :action => "index", :controller => "home", :secret => "I love Jeff Atwood", :user => {name => "Steve", secret => "I steal Joel's pants"}} Is there an elegant way to traverse the hash and remove all the "secret" keys I come across including the subhashes. (...

How is ActiveSupport::SecureRandom secure?

Is the ActiveSupport::SecureRandom secure in the way that it is 'impossible' to figure out random numbers or is it secure in the way that it will return UUIDs? ...

Ruby, Rails, and Windows 7 x64

Just wanted to know if anyone out there has had the same difficulty as I have - I've done a vanilla install of Ruby 1.9.1 using the windows installer, with only a couple of gems: actionmailer (2.3.8) actionpack (2.3.8) activerecord (2.3.8) activeresource (2.3.8) activesupport (2.3.8) bson (1.0.3) jnunemaker-validatable (1.8.4) mongo (1....

What is the difference between strings and symbols in Ruby?

Hello, I used Sphinx plugin for searching and configure it define_index do indexes First_name, :sortable => true set_property :min_prefix_len => 1 end Here First_name is column name. But I was getting error of "search daemon fails to run". And when I made the column name as symbol it runs perfectly. define_index do indexes :...

adding attributes to ruby object dynamically

This probably is a simple doubt but I am very new to Ruby. I have an object created . I want based on some conditional check, to add some attributes to this object. How can I do this. To explain what I want : A=Object.new if(something happens) { #make A have another attibute say age #& store something in A.age } ...

Passing a block into a method

I'm trying to work out how you pass blocks into methods. Basically I have a method, and instead of having the user write this: def user_config @config[:config_value] = "what they want" end I'd like them to be able to do this: user_config do :config_value => "what they want" end But I dont know how to work with a block in t...

Webservice in ruby

Hello, How can I make a webservice in ruby that interact with ruby web application. Thanks! ...