ruby

Form errors not showing in Ruby on Rails.

Hello. I'm trying to create a registration form with Rails. It's working, but it doesn't displays the errors from the validation (it validates, but the errors don't display). Here are my files: # new.html.erb <h1>New user</h1> <% form_for :user, :url =>{:action=>"new", :controller=>"users"} do |f| %> <%= f.error_messages %> <p> ...

How to transfer a binary file or any file to a remote server? - Ruby

The situation is that I'm trying to write a server script that accepts file transfers from a client. I figured out how to make and connect to and from the server using the TCP protocol. However I was wondering how do you transfer a binary file in ruby? I mean you can open a binary file, but what steps are necessary to be able to transfe...

Rails Rendering: Intermittent Resource not found (ActionView::TemplateError)

Hi all, I could use some help figuring out what's going on. Check the log output below -- why would rails treat the two renders differently? Why does one succeed, without any related SQL calls and the second fail -- with an SQL access. (It's not an ActiveRecord model, no SQL should be involved in this render.) Background I have a cu...

Using restclient with multipart posts

Hi all, I'm using restclient for a multipart form to send data to a restful web service (it's Panda video encoding service). The trick though, is that the file I am passing into restclient (Technoweenie branch) is coming from my own form that a user submits. So, lets walk through this. A user posts a file to my rails app. In my control...

DOS window popping up when using IO.popen, etc.

I'm working on a GUI for Windows XP. Everything works great, except when I run an external command through backticks, %x(), IO.popen, etc, I get a DOS window that pops up for a split second. I know this doesn't happen when I've developed on OS X and Linux. Any ideas on how to get rid of it? (Or at least hide it?) I'm using rubyw 1.8...

How to get rid of non-ascii characters in ruby

I have a Ruby CGI (not rails) that picks photos and captions from a web form. My users are very keen on using smart quotes and ligatures, they are pasting from other sources. My web app does not deal well with these non-ASCII characters, is there a quick Ruby string manipulation routine that can get rid of non-ASCII chars? ...

why is my unicode not working under passsenger??

This question contains java and ruby. I have a java program that I make a call to from ruby. This code works under merb perfectly without any modifications. This code will work under irb perfectly by setting $KCODE="UTF8". For the life of me I can not get it to work under phusion passenger -- this is a problem since our production ser...

Ruby On Rails Routing with business logic

Is there a way in the Ruby On Rails Routing framework to make a decision about which controller or action to call based on some logic all within a single route? For example, let's say have a url zip/354 and I want to call the foo action if the integer is even and the bar action if the integer is odd. To use pseudo-ruby: map.connect 'z...

Set array of values on ActiveRecord model from HTML view

I need to have a view able to update an array attribute on a model such that I can dynamically add things on the view to be able to add this. Does that even make sense? Basically a Foo has urls. So in the DB I just have a text datatype that I want to store the comma separated list of urls, and I override the default AR setter and getter...

What's the best way to refactor this Rails controller?

I'd like some advice on how to best refactor this controller. The controller builds a page of zones and modules. Page has_many zones, zone has_many modules. So zones are just a cluster of modules wrapped in a container. The problem I'm having is that some modules may have some specific queries that I don't want executed on every pag...

Cleaning up my controllers, can I have Merb style action defs today?

In Rail 2.3.2 can I have merb style action definitions: Eg: instead of def show @user = User.find(params[:id]) end Can I have: def show(id) @user = User.find(id) end What kind of crazy monkey patching do I need to do to get this working, note I only need this working for MRI so ParseTree is an option. Note: there is a Rai...

why am i getting a SIGTRAP in gdb while debugging Ruby C extension?

I want to use rb_p() to aid in debugging a ruby C extension, but everytime i use it i get a SIGTRAP in gdb! here's an example: (gdb) p user_defaults $3 = 137559900 (gdb) call rb_p(user_defaults) {:fill=>true, :texture=>#} (gdb) n Program received signal SIGTRAP, Trace/breakpoint trap. is_a_hash (try_hash=137560420) at utils.c:65 (...

How to grab a record ID from a search form in rails

Hey guys, I'm very verrry new to rails. I'm using the autocomplete (plugin) text field to browse through titles of my records. When the user selects the record, I'd like to forward them to a custom built URL, based on that record's ID. How should I do this? Thanks! -Elliot To be more specific. I'm trying to make a simple search f...

Getting an ascii character code in ruby - ? fails

I'm in a situation where I need the ASCII value of a character (for Project Euler question #22, if you want to get specific) and I'm running into an issue. Being new to ruby, I googled it, and found that ? was the way to go - ?A or whatever. But when I incorporate it into my code, the result of that statement is the string "A" - no chara...

What is the fully qualified name of a model in Ruby on Rails?

If I have 2 different classes with name User, say one in FooModule and other as a model in app/models/user.rb, how do I make sure I am using the correct one? EDIT: FooModule::User would definitely give me the correct one. What I had meant to ask was: If ApplicationController includes FooModule, would User or ::User still give me app/m...

ruby Rmagick text width

Im using Rmagick in a ruby project to generate a title, All is working fine as below but i need to put an image after the title and i was wondering if there is any way to find out the width of the text i have just drawn? Thanks canvas = Magick::Image.new(600, 18){ self.background_color = '#212121' } gc = Magick::Draw.new g...

How can i save errors in a container inside a model and display it in the controller

Hi guys , i am currently trying to display my errors that i added to user object inside the controller simultaneously with my validation inside the model. like if maybe i have an error in my controller it display it immediately then return and without displaying the errors inside the model, i know that it has to return if my errors are ...

Ruby: The Meta-class and Class Variables

I've been looking at some articles that say that class variables are bad in Ruby. They suggest using the meta-class (or singleton class). This is my sample code class Joe class << self # here we're putting methods in Joe's "meta class" attr_accessor :foo end def self.foo2 end def self.foo2=value end end puts Joe.single...

Ruby, Count syllables

Hey, I am using ruby to calculate the Gunning Fog Index of some content that I have, I can successfully implement the algorithm described here: Gunning Fog Index I am using the below method to count the number of syllables in each word: Tokenizer = /([aeiouy]{1,3})/ def count_syllables(word) len = 0 if word[-3..-1] ==...

Getting Geographical position for a non-GPS j2me phone

Hi is there any way to get the geographical position of a non-GPS enabled phone through a j2me aplpication. I tried to use the JSR179 location API to do this, but I was only able to get it to work on a GPS enabled phone. I also read that doing this is possible on a non-gps phone by getting the cell-ID of the phone, but what do I do afte...