ruby

Is there a neater syntax for displaying a variable in erb?

I'm new to Ruby, and I found the <%= @my_variable %> a little lengthy and less readable. Shouldn't erb have something like ${@my_variable} (like the good old Velocity engine in Java)? ...

find with :include - testing controllers with rspec

Hi, i have some action in my rails application def show @issue = Issue.find(params[:id], :include => [:answers, :comments]) @answers = @issue.answers @comments = @issue.comments respond_to do |format| format.html # show.html.erb format.xml { render :xml => @issue } end end and rspec test def mo...

Enumeration in Ruby on rails

Hello, i am a C# programmer and i am looking in to ruby on rails. but i am having some trouble probably with the mind set or something. I have an object Vote, that object can be Pro, Neutral or con. I would normaly make the vote object have a field some thing like this private VoteEnum voteEnum = VoteEnum.Neutral how on earth can i ...

Generation of formatted files with Ruby in the way how it can be done with PHP

Hi, I use PHP to generate files of some special format, and I have decided to try the same thing with Ruby. To make a file with PHP, I use the following code: <? include 'functions_and_settings.php'; ob_start() ?> some parts of another format <? // php functions generating file content, // including other formatted files ?> some ...

Alternative initialize for a Class to avoid processing already known information

I have a class, Autodrop, that contains several methods , a.o. 'metadata', that call an external API (dropbox). They are slow. However, I already often have that metadata around when initializing the AutodropImage, so I should make the methods smarter. What I have in mind is this: class Autodrop include Dropbox attr_reader :path ...

Location based URL routing in Rails

Hi everyone, I am new to rails. I want to know more about IP based Location, GeoLocation URL routing. I have 2 questions. The first one.. Based on the location of the country, how to you have URL routing? If my IP is from USA, I should be directed towards USA homepage. If I am from UK, I should be directed from UK homepage. If I...

jquery form plugin / rails file upload / plain text respond instead of html

Hello, i'm trying to get a file upload via ajax form to work.. as i am using the jquery form plugin the file upload works well.. but the rendered html in the respond_to js block is returned as plain text. hope someone can help controller: if @visitreport.save flash[:notice] = "Der Besuchsbericht wurde erstellt." respond_to...

Project Euler: Problem #5 in Ruby

I'm trying to solve Problem #5 in Project Euler. The code works for the example, when I check the numbers from 1 to 10 I get 2520 as a result, which is right. But when I check for the numbers from 1 to 20, the code doesn't stop running. Here it is: num = 0 while true num += 1 check = true for i in 1..20 break un...

Suppress PHP Headers running cgi PHP from Ruby

Admittedly, this is a strange problem for me to have, but here is what I'm doing: I've got a Ruby script that is executing a string of PHP code and capturing the output. This is somewhat related to another problem that I had with running cgi PHP from the command line. Here is the Ruby script's source: #!/usr/bin/ruby puts "Content-...

Convert .pdf to images using RMagick & Ruby

I'd like to take a pdf and convert it to images...each pdf page becoming a separate image. There's a similar post here: http://stackoverflow.com/questions/65250/convert-a-doc-or-pdf-to-an-image-and-display-a-thumbnail-in-ruby But it doesn't cover how to make separate images for each page. ...

Dealing with date and time functionality in Rails

Hi guys, I have a date in the database and I want to export it to DATE_TIME.civil() format like the one shown below (I am doing this to export it to a .ics calendar file) DTSTART:20100605T083000 DTEND:20100606T083000 I have two fields in the database one called start_date and two fields start_time and end_time. I want to add...

How to mock/stub a directory of files and their contents using RSpec?

A while ago I asked "How to test obtaining a list of files within a directory using RSpec?" and although I got a couple of useful answers, I'm still stuck, hence a new question with some more detail about what I'm trying to do. I'm writing my first RubyGem. It has a module that contains a class method that returns an array containing a ...

How to delete a gem path?

Hi there, how can I delete the second path (/home/tom/.gem/ruby/1.8) of "GEM PATHS:" ? Here's the output of "$ gem env": RubyGems Environment: RUBYGEMS VERSION: 1.3.5 RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8 RUBY EXECUTABLE: /usr/bin/ruby1.8 EXECUTABLE DIRECTORY: /us...

Have Rails 2.3.x ignore the i18n gem

I have a Rails 2.3.5 project that uses the localization features of Rails. I also happen to have Rails 3 beta installed (which depends on the i18n gem). Rails 2.3.5 will happily handle localization on it's own (without i18n installed), however if the i18n gem is available, it makes use of it. Recently I upgraded my gems and now have ver...

Ruby on Rails worth learning?

Hi, I use PHP+Zend and Java+Wicket and learn Python (so will have Django available). So I want to know if it is worth learning RoR for rapid web-development. Is it much faster building web-apps than with the other approaches or is it neglectable? Or let me rephrase it: What are the facts that make RoR much faster in rapid development...

Resize existing images to new style in paperclip & RMagick

I've been using paperclip to upload and auto-resize photos in my Rails app, and I love it. Only problem is about every other month my crazy manager decides he wants a new size to display the photos in. So I add a new style in my Photo model and all is good for new photos, but the pre-existing photos are now a problem. Now that I'm starti...

How do i ignore rows with unique string while parsing a csv file in ruby

i want to ignore ALL TopLevel, Result,,,,,,,, AddHost,10.1.3.1,,,,,,,, and Flush,,,,,,,,, AddHost,10.1.3.4,,,,,,,, from TopLevel, Result,,,,,,,, AddHost,10.1.3.1,,,,,,,, Add,10.1.3.1,43172 Add,10.1.3.1,44172 Add,10.1.3.1,4172 Add,10.1.3.1,432 Add,10.1.3.1,435472 Flush,,,,,,,,, AddHost,10.1.3.4,,,,,,,, ...

Rails Cucumber URL hosts

So... I have this URL: example.com which works in my browser, cause in my hosts file i have it set to 127.0.0.1 example.com And that works in my browser... but not in cucumber. Any ideas? ...

Rails Fields For Code Sample

Hi, Can someone explain the following code sample what does "album[photo_attributes][]" mean I found this code here http://infrastacks.com/?p=57 <div class="photo"> <% fields_for "album[photo_attributes][]", photo do |p| %> <p> <%= p.label :Photo %><br /> <%= p.file_field :data, :index => nil %> <%= link_to_function "delet...

In Sinatra, best way to serve iPhone layout vs. normal layout?

I'm writing a Sinatra app which needs to render different layouts based on whether the user is using an iPhone or a regular browser. I can detect the browser type using Rack-Mobile-Detect but I'm not sure of the best way to tell Sinatra which layout to use. Also, I have a feeling that how I choose to do this may also break page caching....