ruby

redirect_to in private methods

I have an action that is calling a private method. If an error occurs in this private method *redirect_to* is called. The issue is that it gets to *redirect_to* and according to the logs it is redirecting but doesn't on the client end and results in an error. Any suggestions? Thanks! ...

I can send an email from my Rails app, but not an SMS text through an email gateway...

I have application that needs to send emails and sms text messages. It sends emails just fine, but when I try to send text messages using email gateways (for verizon, [email protected]) I get nothing. I have texted the phone using though the email gateway using my gmail account, so I know it works. I would just think that from my ap...

Rails: How do I keep a complex app RESTful?

I always try to make my applications as RESTful as possible but I've recently begun working on a complex project that requires multiple additional methods in my controller. I normally achieve this by adding another :collection to the route but it seems like a workaround and in on scenario I have 5. Are there any best practices for han...

Transferring variables between models using a view.

I am creating a very simple book review site and it needs the ability to allow the user to add little comments about a book. Now I have my two tables, one for the book and one for the comments and now need a way to transfer data between the two because i find the way rails handles things quite puzzling. So my book model contains "has_ma...

How do you create a custom subclass of IO in Ruby?

How do I make my own class that can be substituted for IO in order to e.g. redirect/capture input/output for some code that accepts an IO-like parameter? IO itself seems to be coupled to OS file descriptors and the only class I know of that mimics it without subclassing it is StringIO, which seems to just reimplement the entire interface...

Rails error "NoMethodError" - My first ruby app

Hi, I am absolutely and totally new to rails, so the answer is probably very simple. Here goes: My page is generating this error NoMethodError in Tasks#new Showing app/views/tasks/new.erb where line #3 raised: undefined method `tasks_path' for # Here is the view: <% form_for(@task) do |f| %> <%= f.error_messages %> <%= f...

Compression libraries for Ruby?

Are there any open-source compression/decomp libraries available for Ruby? Has anyone implemented LZW? Or, are there any open-source libraries that use a compression component which could conceivably be extracted for independent use? EDIT -- thanks for the answers! I should have mentioned that what I have to compress are long strings t...

Nested object creation with JSON in Rails

How do I pass JSON to a RAILS application so it will created nested child objects in a has_many relationship? Here's what I have so far: Two model objects. class Commute < ActiveRecord::Base has_many :locations accepts_nested_attributes_for :locations, :allow_destroy => true end class Location < ActiveRecord::Base belongs_to :c...

macruby: Using ruby method as AXObserverCallback

I trying to watch out for a text field to change, using macruby. AXObserverCreate expects an AXObserverCallback as parameter. How can I pass a ruby function as a callback? My function in AX.m: + (AXError) addNotificationWithElement: (AXUIElementRef) element forEvent:(CFStringRef) event_type callback:(AXObserv...

Not sure where (model or controller) to define my find method

(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a public method in my albums controller: <% albums_feature = find_albums_with_feature(feature.id) %> It generates a NoMethodError. So I copied the method into my Album model and tried calling it from the view as: <% albums_feature = Album.find_albums_w...

Ruby Difference Between Integer Methods

What is the difference between 10.6.to_i and 10.6.to_int ? ...

What's the quickest way for a Ruby programmer to pick up Python?

I've been programming Ruby pretty extensively for the past four years or so, and I'm extremely comfortable with the language. For no particular reason, I've decided to learn some Python this week. Is there a specific book, tutorial, or reference that would be well-suited to someone coming from a nearly-identical language, or should I jus...

Django or Ruby-On-Rails?

I have been looking for jobs right now. And, most of the companies require RoR or Django experience. I don't know both ... number of organization working in RoR is greater than Django ... but, I prefer django coz of Python ... What do u coders/recruiter suggest me to know? ...

Mac OS X: Spawning a Ruby Tk window that has focus

I'm trying to spawn a Tk window from ruby script using ruby's Tk module. It works, but I cannot figure out a way to focus the spawned window. It's frustrating. If I run this code from terminal, as in $ruby screenup.rb the window spawns behind the terminal window. If I run as a shell script in Quicksilver, two windows spawn. One is t...

Submitting Rails Form on a Radio Button Selection

I have the following rails form (which works) but I want to remove the submit_tag and have the form submit as soon as a radio button selection is made. How do I do that? <% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do %> <p> <% for i in 1..10 do %> <%= radio_button_tag :rating, i %>&nbsp;...

Replacement for rdoc usage

According to this post, RDoc::usage is not currently available in ruby 1.9. Are there any good replacements available? I'd be interested to hear what's available from the standard install as well as what's available from gems. ...

Ruby on rails path helpers

I know this is a minor issue, but why, if you use scaffolding in RoR, can you use lines like 'new_*model name here*_path' in link tags, but without using scaffolding, I get a NameError? For example, I have a simple address book app that uses basic CRUD operations. I am a RoR beginner but wanted to build an app without scaffolding and t...

Ruby newbie question: hashes

i have the following class test hash={} def printHash puts hash[1] puts hash[2] puts hash[3] end end test.new.printHash this prints: 1 0 1 Why does this happen? how can i test whether or not i have put something in that spot of the hash? or am i missing something ...

Server prefix and rails routes

When i'm starting the server with the path option script/server --path=/myapp while having a route map.route 'foo', :controller => 'bar', :action => 'buzz' then ActionController::Routing::Routes.recognize_path('/myapp/foo') raises an error "No route matched ..." Question: How can i make Rails built-in routing recognize with p...

How do I access the Rack environment from within Rails?

I have a Rack application that looks like this: class Foo def initialize(app) @app = app end def call(env) env["hello"] = "world" @app.call(env) end end After hooking my Rack application into Rails, how do I get access to env["hello"] from within Rails? Update: Thanks to Gaius for the answer. Rack and Rails let y...