4
голосов
1ответов
7518 просмотров

Rails Test & Mocha: How to stub specific model - conditional any_instance?

I want to stub just a specific model, but not only a specific object and not every instance E.g. Given class 'Person' with attributes 'name' (string) and 'cool' (boolean). We have two models: person_bill: name: bill cool: false person_steve: name: steve cool: false Now I want to...

2
голосов
2ответов
7001 просмотров

Ruby: How to convert a string to binary and write it to file

The data is a UTF-8 string: data = 'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08' I have tried File.open("data.bz2", "wb").write(data.unpack('a*')) with all kinds of variations for unpack put have had no success. I just get the string in the f...

203
голосов
7ответов
143176 просмотров

How do I encode/decode HTML entities in Ruby?

I am trying to decode some HTML entities, such as '<' becoming '<'. I have an old gem (html_helpers) but it seems to have been abandoned twice. Any recommendations? I will need to use it in a model.

0
голосов
2ответов
710 просмотров

form_for using :symbol not working, error [Only get, put, and delete requests are allowed]

When submitting a form to create a new object i get an error message when submitting the form. When i use the same form but then with an instance variable everything seems to go fine, any clue why the submit with the :symbol fails? The error message says: Only get, put, and delete requests are a...

4
голосов
2ответов
1790 просмотров

How to check if a template exists in Sinatra

In the Sinatra ruby framework, I have a route like this: get '/portfolio/:item' do haml params[:item].to_sym end This works great if the template that exists (e.g., if I hit /portfolio/website, and I have a template called /views/website.haml), but if I try a URL that doesn't have a template...

2
голосов
4ответов
1665 просмотров

Looking for an open source CMS with excellent internationalization and localization

Can anyone suggest a CMS able to offer the following features: Free/open source Support for multiple languages (both frontend and backend) Support for translating content (i.e. an article can have 1+ translations) Support for different content types, namely pages, articles (timestamped, with co...

2
голосов
3ответов
2668 просмотров

How to return a Ruby array intersection with duplicate elements? (problem with bigrams in Dice Coefficient)

I'm trying to script Dice's Coefficient, but I'm having a bit of a problem with the array intersection. def bigram(string) string.downcase! bgarray=[] bgstring="%"+string+"#" bgslength = bgstring.length 0.upto(bgslength-2) do |i| bgarray << bgstring[i,2] end return bgar...

3
голосов
9ответов
1360 просмотров

How should I copyright and license my free software?

I'm all new to the open source free software thing, but any way I'm going into it pretty well (I guess!!). Now the thing is: in the way to distribute my program, I'll have to distribute my source code, so it will be a (.gz) with an installer for sure, or maybe a (.deb). My questions are: (I k...

2
голосов
1ответов
1324 просмотров

Ruby GServer performance

I tested the performance of GServer by implementing the most basic server and checked how many requests per second it could handle. The result was 81. This is very slow compared to the 9900 requests per second that my most basic TCPSocket server can handle. Am I doing something wrong or is GServe...

0
голосов
2ответов
1715 просмотров

Can't get XML data via HTTPS with Ruby

I'm trying to download account transactions (an XML file) from a server. When I enter this URL from a browser: https://secure.somesite.com:443/my/account/download_transactions.php?type=xml it successfully downloads a correct XML file (assuming I've already logged in). I want to do this progra...

2
голосов
2ответов
1016 просмотров

How to get the nested modules dynamically from an object?

given: module A class B end end b = A::B.new we want to be able to get the module nesting as an array. This can be done if the class is known in advance. eg: module A class B def get_nesting Module.nesting # => [A::B, A] end end end But, how to do it for an arbitr...

8
голосов
4ответов
5357 просмотров

how can you loop through multiple arrays parallel?

i have 4 arrays. ["one", "two", "three"] ["1", "2", "3" ["un", "deux", "trois"] ["ichi", "ni", "san"] is it possible to concatenate each element in their respective arrays ? so i end up with single lines of string like like "one, 1, un, ichi"\n "two,2, deux,ni"\n and so on... is it possi...

0
голосов
2ответов
1673 просмотров

ruby aws-s3 bucket problem

I'm trying to test the aws-s3 gem for ruby, but I'm getting a weird reply: I connect, and can see I am connected, then I run: AWS::S3::Service.buckets and get the [] reply as expected, then I create a bucket AWS::S3::Bucket.create('some-name') and get true as a reply, then I run AWS::S3::Service...

-2
голосов
2ответов
165 просмотров

Unexpected array behavior

The following modify method somehow modifies the whole @x array instead of just simply generating another element to be pushed later. How come? def modify i, s t = @x[-1] t[i] = t[i] + s t end @x = [ [10, 12] ] @x << modify(0, 1) puts @x Edited The following code have done the tr...

1
голосов
2ответов
191 просмотров

Thread lockup in ruby with Soap4r

This is related to a question I asked here: Thread Locking in Ruby (use of soap4r and QT) However it is particular to one part of that question and is supported by a simpler example. The test code is: require 'rubygems' require 'thread' require 'soap/rpc/standaloneserver' class SOAPServer &lt...

6
голосов
4ответов
11089 просмотров

Store image in database using rails paperclip plugin

I have an application that uses the Paperclip plugin for image upload. Now that app should get deployed to an host(heroku) which has a read-only file system. Can I somehow tell paperclip to store the images in the database?

1
голосов
1ответов
2839 просмотров

custom before/after hooks in rails for non standard actions?

I have a controller with some non standard actions, like admin, moderate, etc. I tried using the hook before_admin it that didn't work. Is it possible to use these hooks for my custom actions? Sorry for the lack of clarity. Say I have something that I want to happen before saving..it's easy to j...

1
голосов
3ответов
857 просмотров

Ruby on rails deployment with Vlad on windows

I am having a problem with Vlad on windows. After calling rake vlad:deploy I am getting the following: uninitialized constant Fcntl::F_SETFD After googling for a while I figured out that there is problem with open4 gem that is not suitable for Windows and I should use popen4 gem instead. I insta...

0
голосов
1ответов
152 просмотров

performance/ruby/rails/db question

I'm creating an online bookmaker odds comparison site for soccer and I'm wondering how to calculate the best odds in Ruby/Rails. I have two models: fixture and odds Fixture has home and away teams, and odds model has bookmaker ID, home odds, draw odds and away odds. I have selections which jus...

0
голосов
1ответов
150 просмотров

change the return of to_param by action? or, terribly broken edit action if perma-url is returned instead of id

I did some stuff to have to_param return a perma-url so I'd have seo friendly links. Upon creation and update it will generate and return the perma-url in a to_param method that I put in the model. However this causing me some grief in other areas. I have a form that looks like this: <% @a...

14
голосов
5ответов
4586 просмотров

Cucumber/Webrat: follow link by CSS class?

is it possible to follow a link by it's class name instead of the id, text or title? Given I have (haha, cucumber insider he?) the following html code: <div id="some_information_container"> <a href="edit" class="edit_button">Translation here</a> </div> I do not want ...

4
голосов
2ответов
1704 просмотров

Is validates_presence_of necessary if using validates_length_of?

In an ActiveRecord model is it considered best practice/necessary to use validates_presence_of when also using validates_length_of? For example: class Company < ActiveRecord::Base validates_presence_of :name validates_length_of :name, :in => 5..30 end To me, it seems redundant. Ha...

0
голосов
4ответов
321 просмотров

Array to Hash or 2 binary element Array

I'm seeking the most concise way to do this Given the following Array: ['a','b','c'] how to get this: {'a'=> 1,'b'=> 2, 'c'=> 3} and [['a',1],['b',2],['c',3]] I have few solutions at mind, just want to see yours :)

4
голосов
2ответов
704 просмотров

How can I scope acts_as_taggable_on_stereoids by Account?

If I have my website logically split into accounts (eg. acme.mywebsite.com, xyz.mywebsite.com), how can I implement act-as-taggable-on-steroids and have the tags scoped by the current account ? To give little more details, if I am accessing acme I don't want to see tags from xyz subdomain. I ha...

0
голосов
1ответов
68 просмотров

writing an attribute to my through table with validation?

I have been trying to do this for ages and can seem to grasp it. hope someone can help ? i have a 'message' model that has many through 'distribute' relationship to a 'contact_detail' model. basically a message can have many contacts associated with it and a contact can have many messages. I ...

0
голосов
2ответов
1013 просмотров

run a ruby script from delphi via shellexecute

I've written a little ruby script that lets me send emails by calling it along with some command line parameters. At the command line, this works: ruby.exe mail_it.rb fromaddr="[email protected]" tolist="[email protected]" But try as I may, I can't get it to work in Delphi 2007 for Win32....

0
голосов
4ответов
189 просмотров

how to remove all [d+] except the last [d+]?

i have a string like /root/children[2]/header[1]/something/some[4]/table/tr[1]/links/a/b and /root/children[2]/header[1]/something/some[4]/table/tr[2] how can i reproduce the string so that all the /\[\d+\]/ are removed except for the last /\[\d+\]/ ? so i should end up with . /root/chil...

0
голосов
1ответов
448 просмотров

Fastest/shortest way to build unique tree in Ruby?

What is the fastest/shortest/one-liner (not possible :p) way to build a unique tree of elements from a tree where many of the elements are duplicated/missing in some nodes, given the tree has a defined set of nodes (which we'd use this algorithm to figure out so we don't have to manually do it). ...

7
голосов
3ответов
4880 просмотров

Fastest/One-liner way to remove duplicates (by key) in Ruby Array?

What's the fastest/one-liner way to remove duplicates in an array of objects, based on a specific key:value, or a result returned from a method? For instance, I have 20 XML Element nodes that are all the same name, but they have different "text" values, some of which are duplicates. I would lik...

0
голосов
3ответов
98 просмотров

how to do the following in ruby?

I need to grab a string like "/html/body/a" i need to check the last portion, in this case "a" after the final "/" how can i do this ? how can i regex match for the last item after the final "/" ?