With autospec / cucumber / capybara running my feature tests I get this line even after going green:
(eval):1:in `initialize': can't convert String into Integer (TypeError)
Anyone know what this is? I thought it was me, then heard another dev was seeing it to, and when googling I see it in the screen logs on various issues at the capy...
If a user tries to submit a form or access a service that uses something such as the following underneath the hood:
Model.find(params[:id]) # if model does not exist, throw ActiveRecord::RecordNotFound
If an instance cannot be found, an exception is thrown. Yet I rarely see folks wrap that statement around in a begin/rescue block, eve...
I'm currently in the design stage of a reporting system which will create comparison reports of screens for a fleet of ATM's (being developed in Ruby on Rails).
The data collected from each ATM is stored in XML which contain File Name, Date Modified, Size and Check-sum. These files are then compared with a Master file and report on extr...
Okay, this code gives me exactly what I want but it seems that it could be cleaner, so here is the code:
colour = ["red", "white", "orange", "black"]
x=[]
colour.each_with_index do |c, i|
x[i] = "<a href='http://#{c}.test.com'>#{c}</a>"
end
tags2 = x.join(", ")
p "The code ==>#{tags2}<=== "
Any takers?
...
So, I'm building quick and dirty search functionality in my first rails app. I'm doing a query and returning a list of objects. e.g.
@articles = Article.find_by_sql("select * from article where title like "%test%" or title like "%foobar%")
So, the articles collection will return a lot of data, some of it matching my search terms bet...
I'm faced with an interesting task:
Our transport guys have to monitor a 3rd-party webpage the entire day, clicking every 5 seconds on a button, to refresh the page and get available transport slots. The slots section is only updated when the button is clicked. When slots become available, the available slot label changes from "0" to "1...
Hello,
So I need to run a loop in Ruby to pass some strings into SQLite. Basically I have a table that looks like this:
pID Data
1649,1650,1651|Some data
1643,3|some more data
23,4,5,6,7|More data
Now in my SQLite queries, I will sometimes need to pass all the pIDs for a given line through as one whole string, which I ca...
I want to accomplish the same thing Rails has done, to store configurations in rb files that are read by the application:
# routes.rb
MyApp::Application.routes.draw do |map|
root :to => 'firstpage#index'
resources :posts
In rails the methods "root" and "resources" are not defined in the object "main" scope.
That means that these ...
I want to split the string "hello+world-apple+francisco-rome", into ["hello", "+world", "-apple", "+francisco", "-rome"].
String::split actually loses the splitting element. Anyone can do that?
...
Hi, I have a nested loop2(check2) in loop1(check1) but it seems that nested loop2(check2) only runs once.
Both loops contain the same array. This script is used to check for a duplicate id in check1.
check1=["0", "0", "0", "1", "1", "2", "3", "4", "5", "100", "4294967294", "9", "11", "6", "200", "7", "201", "811", "202", "204", "3000",...
Take this scenario. I have a Google Analytics tracking code, and I only want it to show up in Production mode. So I might have two scenarios like this:
Scenario: Don't embed tracking code in development or test mode
Given the app is not in production mode
When I go home
Then I should really not see the tracking code
Scenario: Emb...
I thought I was following this RoR tutorial to a T, but apparently not. They instructed that we write this code into apps/views/index.html.erb
<h1>Listing posts</h1>
<table>
<tr>
<th>Name </th>
<th>Title </th>
<th>Content </th>
</tr>
<% for post in @posts %>
<tr>
<td><%=h post.name %...
In the documentation of cancan it shows how to fetch all accessible records (in http://wiki.github.com/ryanb/cancan/fetching-records) in this way:
@articles = Article.accessible_by(current_ability)
but what is current_ability? I've tried passing the current user which I'm using for authentication and authorization, but I've got this e...
Python has really elegant syntax for checking a value against several patterns.
2 in [1,2,4] #=> True
6 in [1,2,4] #=> False
Order in Ruby version just feels wrong:
[1,2,4].include?(2)
I understand that include? makes a lot more OO sense than 2.included_in?([1,2,4]), I still don't like it. Ruby even has in keyword but it seems to o...
Hi,
I have written a backend for creating ftp-users for proftpd via MySQL-module. After deleting a user from database some OS-specific tasks are left: deleting or moving the files of the user on file system level ("rm -R /home/dir/of/deleted/user").
The backend runs under linux user A, the ftp root belongs to user B. Therefore and for ...
I have a text file which I intend to convert to a CSV (in this case) format. How do I create a proper RSpec test to see if the output will be in the proper format for the following scenario?
This is my code:
class ProcessLog
@@log = Array.new
def read_log(log)
if File.exists?(log)
f = File.open(log, "r")
...
Im reading Metaprogramming in Ruby.
Here are two code snippets from the book:
my_var = "Success"
MyClass = Class.new do
puts "#{my_var} in the class definition!"
define_method :my_method do
puts "#{my_var} in the method!"
end
end
MyClass.new.my_method
⇒ Success in the class definition!
Success in the method!
and:
def...
Here's a little copy/paste from fxri. Why is this happening and how do I fix it? Ruby version is; ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] on 64 bit windows 7.
irb(main):334:0> pp "a"
NoMethodError: undefined method `<<' for #<FXIrb:0x6229524>
from ..../Ruby/lib/ruby/1.8/prettyprint.rb:146:in `text'
from ..../Ruby/lib/ruby/...
I just wrote this piece of code but I'm not quite happy about it.
data = {}
options.each{ |k,v| data.merge!({k.to_s => v}) }
Basically I have:
{:a => "something", :b => "something else", :c => "blah"}
... and I want ...
{"a" => "something", "b" => "something else", "c" => "blah"}
... in order to send it to a gem that do not hand...
There were two good reasons why Ruby 1.8 didn't support certain kinds of overloading like ||/or, &&/and, !/not, ?::
Short circuit semantics cannot be implemented with methods in Ruby without very extensive changes to the language.
Ruby is hard coded to treat only nil and false as false in boolean contexts.
The first reason doesn't ap...