I simply want to upload an image to a server with POST. As simple as this task sounds, there seems to be no simple solution in Ruby.
In my application I am using WWW::Mechanize for most things so I wanted to use it for this too, and had a source like this:
f = File.new(filename, File::RDWR)
reply = agent.post(
'http://rest-test.her...
In a Ruby web application I want users to be able to upload documents. If the user uploads a Microsoft Word file (.doc) I want Ruby to count the number of pages in the file. It would be even slicker to get the number of words, but the number of pages will do.
How would I do that? Is there a Ruby library/gem that can do that for me? Is i...
Hi,
I'm exploring Sinatra and I want to use sessions but I don't want them to be stored in a Cookie, I found Rack::Session::Pool which works very well.
Now I want sessions to expire after a certain duration but I don't understand how to instanciate the Rack::Session::Pool and them use it in Sinatra.
Any Clue ?
...
Hey,
I am working on a project that involves a url "forwarder" (like bit.ly or tinyurl.com, but we don't really need it to be short).
For that, I need to "generate" alphanumeric strings (I explicitly want alphanumeric) to map to each url. One of the options would be generate a random string and store it somewhere. However, I'd like to ...
I would like to build a string from a byte value.
I currently use:
str = " "
str[0] = byte
This seems to work fine but I find it ugly and not very scalable to strings longer than 1 character.
Any idea?
...
I'm fairly new to Ruby on Rails, and I have a project with a "Set" model. This is in Rails 2.3.2. Now the problem is that it can't find any methods on that model's class at all. For example: "undefined method find' for Set:Class" or "undefined method errors' for #". It seems to be trying to find those methods on the Ruby "Set" class inst...
I am running a Rails app so now I am trying to remote connect to mysql and I am getting this error
Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 0
...
How can I, very simply construct a hash in ruby using something simple like "times"
I have a @date (ie = Date.today) and then a number of days... say 5
5.times { |i| @date_range[:day] = (@date+i).strftime("%Y-%m-%d") }
I know there's got to be something super simple that's missing.
Thanks...
...
I have implemented a sorting algorithm for a custom string that represents either time or distance data for track & field events. Below is the format
'10:03.00 - Either ten minutes and three seconds or 10 feet, three inches
The result of the sort is that for field events, the longest throw or jump would be the first element while for ...
I want 'logical OR' dynamic finders in ActiveRecord. Anybody seen such a thing?
So in the spirit of something like this..
User.find_by_name_and_email("foo", "[email protected]")
.. you could do stuff like this..
User.find_by_username_or_email(user_input)
...
Is it possible to debug a Rails application in a similar way to a Java application - setting breakpoints and stepping into the code?
What are the best tools for this?
I have a hybrid Java/Ruby on Rails application which I can run in Eclipse or Netbeans.
I would like to step into some code in this app and try to figure out the cause of...
Hi All,
Quick question regarding the use of "SELF" inside a module or library. Basically what is the scope/context of "SELF" as it pertains to a module or library and how is it to be properly used? For an example of what I'm talking about, check out the "AuthenticatedSystem" module installed with "restful_authentication".
Best
NOTE:...
Hi All,
I'm looking for a quality Administrative plugin for Rails. It seems that most of the existing plugins/gems (e.g. "restful_authentication", "acts_as_authenticated") revolve around self-signup, etc. However, I'm looking for a full-featured Administrative/Management role-based type of solution -- but not one that's simply tacked ...
Should I use if defined?
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
Or ||=
@current_user_session ||= UserSession.find
I noticed the if defined? method being used more and more recently. Is there any advantage to one over the other? Personally, I prefer ||= for readab...
I am extremely new to ruby and just trying to use it to do some basic scripting. Namely telnet into a machine and use the dos ftp client to pull some files over.
The problem that I have is when I try to telnet into the machine manually (from command prompt) I get the following message:
Welcome to Microsoft Telnet Client
Escape Cha...
I'm attempting to create a facebook app and went through the book http://pragprog.com/titles/mmfacer/developing-facebook-platform-applications-with-rails. Everything works fine on my development machine when I have my canvas render method set as fbml. But, for various reasons I want to build an app with an iframe. When I set my app to...
My selenium tests like to fails randomly. As an example I have this scenario
Scenario: I should be able to edit a user
Given I created a user with the login "[email protected]"
And I am viewing the user with login "[email protected]"
Then I should see "Edit this user"
When I click "Edit this user"
Then I should be editing the us...
I'm attempting to unzip a file with several files that may or may not already exist in the target directory. It seems the default behavior is to throw an exception if the file already exists.
How do I unzip to a directory and simply overwrite existing files?
Here's my code:
begin
Zip::ZipFile.open(source) do |zipfile|
dir = zip...
Hi All,
I've read many of the existing questions/threads on this subject, but keep in mind that none of them have directly addressed my issue. Also keep in mind that this is NOT a situation for database.yml as I won't know the DB info in advance.
That said, I need a solution for DYNAMICALLY connecting to multiple databases in a Rails ...
I have a set of rake tasks where I need to invoke capistrano at some point. Edwin Goei's blog suggests shelling out to capistrano via "sh".
Is there a simpler way? It would seem you should be able to call the appropriate tasks programmatically. Thanks in advance.
...