ruby

Rails: Split and wrap each character in a string?

I have something like: <%= @votes %> With just outputs a string like: 123 Is there a simple way to wrap each character with some html with a helper? <span class="outerclass"> <span class="innerclass"> 1 </span> </span> <span class="outerclass"> <span class="innerclass"> 2 </span> </span> <span class="outerclass"> <...

can I declare an array where one of the array elements is undeclared variable? (ruby)

#input_from_the_net = "" my_array = [ ["Header name" , input_from_the_net] ] input_from_the_net = "a value scraped from the net" puts "#{my_array[0][0]} is #{my_array[0][1]}" EDIT: I use the variable input_from_the_net later on in the loop and assign its value into a hash. That hash is then stored inside another hash. If I use inpu...

Replace white space with AND in ruby

I have someone entering a form with some string input. What I need to do is replace any white space in the string with " AND " (no quotes). What's the best way to do this? Also, how would I go about doing this if I wanted to remove all the whitespace in the string? Thanks ...

Assistance with Some Interesting Syntax in Some Ruby Code I've Found

I'm currently reading Agile Web Development With Rails, 3rd edition. On page 672, I came across this method: def capitalize_words(string) string.gsub(/\b\w/) { $&.upcase } end What is the code in the block doing? I have never seen that syntax. Is it similar to the array.map(&:some_method) syntax? ...

[Rails] Using find method to find NOT matching

I'm trying to look up a User by group_id. My method looks kinda like this: User.find(:all, :conditions => {:group_id => '90a39597a1aa3ec65fccf29ae05d9b6aefbfea6b', :id => !current_user.id}) The :id condition doesn't make sense because I don't know the syntax for this part. How would I find a user by group_id and :id which doesn't matc...

how to code a condition: 'can this string be converted into a date type'? (ruby)

can I code this condition in ruby somehow? I need to know if a string can be converted into a date variable. The only way how to do it is Date.parse("my string") and exception. Is there any other way? date_scraped_from_the_net = "20 Dec 2009" or it could be "today" if date_scraped_from_the_net is not a date type needs_to_be_updated ...

See if a ruby string has whitespace in it

I want to see if a string has any white space in it. What's the most effective way of doing this in ruby? Thanks ...

echo in inf-ruby

I am trying to get inf-ruby to work in Emacs. For the most part it works fine, except for the very annoying habit of echoing every input entered. Does anyone know what could be wrong? I am using Carbon Emacs on OSX 10.5 with the default Ruby 1.8.6. My irb version is 0.9.5 The odd bit is that inf-ruby worked perfectly one time I open...

Phusion Passenger on Ubuntu 8.10: how to setup gem directory and users?

I am actually running phusion passenger on ubuntu for a while. today i updated Ruby Enterprise Edition to the latest version - now it seems i have to reinstall all the gems that were installed on the system. so here are my questions what is the best way to setup phusion passenger and ruby enterprise edition to easily maintain gems afte...

What's the difference between these two Ruby snippets?

Snippet 1: module A def cm(m,ret) class_eval do define_method(m.to_sym) do return ret end end end end and snippet 2: module B def cm(m,ret) class_eval do "def #{m} #{ret} end" end end end The methods defined in these modules are to be used to create methods on a class, that returns cer...

Installing Ruby on Rails in windows 7

hi! I saw some ruby tutorials today and like to learn it. The problem is that i'm stuck with the installation process! :( I can't get a clear picture on how to install RoR. For example, to write php code i installed wamp and straight away started writing php scripts. And i'm using Dreamweaver CS4 as an IDE. Can anyone enlighten me : ...

Machinist vs FactoryGirl - pros and cons

Hi, I'm working with factory_girl, but looking at the machinist gem. Could you tell me please - what are the pros and cons of migrating to machinist? Have you compared those libs? ...

chronic gives me error after installation (ruby)

I run ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] I had to upgrade RubyGems so I run 1.3.5 now then I istalled chronic (0.2.3) but I only receive ./chronic.rb:3: uninitialized constant Chronic (NameError) from E:/prog/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from E:/prog/r...

How to make instance variables private in Ruby?

Is there any way to make instance variables "private"(C++ or Java definition) in ruby? In other words I want following code to result in an error. class Base def initialize() @x = 10 end end class Derived < Base def x @x = 20 end end d = Derived.new ...

CSS-Redundancy when using LESS and its @import

I really like the idea and the concept of LESS. Yet I stumbled upon a bug, which i reported quite a while ago to the author but did not yet get any feedback. Maybe it's just me who is doing something wrong. My application.less-File that looks similar to this: @import "reset"; @import "config"; @import "header"; @import "forms"; […] ...

How to simulate the effect in stackoverflow on RoR?

I want to make a notification like this : it is only a flash[:notice] with some CSS trick in RoR? or it there any other trick on this? ...

How to create a resetable "process" or "thread" in Ruby?

I've got this script, that uploads some files, connects via ssh and does some stuff on the remote server, kinda like deployment script, and I want to make it run whenever I want to and to be able to reset it in the middle of processing. def deploy # some stuff happens here end def do_deploy $deploy.kill! if $deploy $deploy = Th...

Is there any way to access the expression from within a ruby case statement?

Hi All, I would like to access the case statements expression from within a then clause i.e. food = "cheese" case food when "dip" then "carrot sticks" when "cheese" then "#{expr} crackers" else "mayo" end where in this case expr would be the current value of food. In this case I know, I could simply access the variable food, howeve...

How to change my parameter format?

Here is my Ruby Code: <%form_tag orders_path, :method => 'get' do%> From <%= date_select ("from", "", :start_year => 2010, :order => [:day, :month, :year])%> To <%= date_select ("to", "", :start_year => 2010, :or...

How does a view work (MVC)?

I'm working on a web-app without a framework right now, and I'm trying to structure it as a MVC app. The problem is, there are some technical aspects of MVC apps that escape me. Primarily, how should a view be build? I'd like to use a markup language like eRuby or #haml, but I don't know how exactly they work and how to implement them ...