ruby

Two controllers for one shared view in Ruby on Rails

I have two controllers for two respective models, by example, photos and categories. index and show methods are very similar in each controller, and the views are identical. What is the best method for share the view by the two models? I've though two options: Use a helper. In the helper will put the code for the view, and will call t...

Moving business rules into model

I asked a question earlier which elicited some great responses. Here's the earlier question On the back of some advice given there, I've tried moving the following controller logic if params[:concept][:consulted_legal] == 0 && params[:concept][:consulted_marketing] == 1 @concept.attributes = {:status => 'Awaiting Compliance Approva...

Ruby string mutability

This may be a bit of a nooby question, I have been trying to get better at ruby recently, and started reading the fantastic The Ruby Programming Language. Something that was mentioned is that string literals are considered mutable, so in a loop it is better to use a variable then a literal, as a new string will get instantiated at every ...

Netflix API, OAuth, and Ruby Issue

Hi, I am trying to use oauth with the rares-branch Ruby gem. I keep getting the error: instance of OAuth::Consumer needs to have method `marshal_load' My code, activate.rb is below. Any thoughts on how to fix this? THANKS! -Henry require 'oauth/consumer' def index @consumer = OAuth::Consumer.new("CONSUMER KEY","CONSUMER SECRET", ...

Rails has_many_polymorphs in reverse?

So I have some models set up that can each have a comment. I have it set up using has_many_polymorphs, but I'm starting to run into some issues where it's not working how I think it should. For example: class Project < ActiveRecord::Base end class Message < ActiveRecord::Base has_many_polymorphs :consumers, :from => [:projects,...

Simple Rails Q: Where is this variable defined?

I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold Post then this link works in one of the erb files: <%= link_to "My Blog", posts_path %> WHY? I've looked for "posts_path" in the whole app and it's nowhere to be found. On the other hand, this <%= link_to "My Blog", home_path %> does no...

Could proc get executed without using call method?

I am sorry to bring out a separate question from here, but it really confused me these days. Here is the definition of add_mapping method: def add_mapping(regexp, &proc) @test_mappings << [regexp, proc] end How could proc here get executed and return result without using call method? Thanks ...

in rails using will_paginate and partials

I have a collection of people that is paginated with will_paginate @people = Person.paginate :page => params[:page], :limit => 10, :conditions => ['company_id = ? ' , @company.id ] The people are shown on the company/view page and rendered with a partial. Note that the partial is in the views of 'people' <%= ...

256 colors, foreground and background

This is a tale of two scripts and is related to a previous question. The two scripts are at http://gist.github.com/50692. The ansi.rb script displays all 256 colors on all 256 background colors. The ncurses.rb script displays all 256 foreground colors but the background displays the basic 16 and then seems to cycle through various attri...

What does the "RAILS_GEM_VERSION" setting do exactly?

What is the purpose of the RAILS_GEM_VERSION setting in config/environment.rb? Is it supposed to stop your app from running under an unexpected version of Rails? I just keep Rails updated to the latest release on my laptop and in production. Since I do that, can I comment out RAILS_GEM_VERSION or should I set it for some reason? ...

Friendly Form Validations (Rails)

I checked out both of these previously-asked questions, and they're a help but not a full solution for my case. Essentially I need to validate a user-submitted URL from a form. I've started by validating that it begins with http://, https://, or ftp:// : class Link < ActiveRecord::Base validates_format_of [:link1, :link2, :link3, ...

What is the Linux friendly MVC Web based framework with highest amount of developers?

MVC is a great concept, but choosing among all the variety and flavors out there is not a simple task. Very soon we are going to start a new web development project and we want to do it in a solid, enterprise class, long lasting language. We are choosing linux friendly language. Even we know that MONO will allow us to run .NET in linu...

Is variable permanence available in Ruby?

In Matlab, I recall being able to declare an array and initialize it and it resides in memory during the entire Matlab session. I could copy it, modify it, and run it through tests. Is this option available in Ruby? Basically I want to create and populate an array of 12 million 32-bit integers. Then I want to run code that accesses t...

How do I check if a controller action is already redirecting?

OK, as is often the case, I have a controller action in my app that is protected from unauthorized access by a before_filter. The only thing is that I need to redirect this action if another condition is true: class Payment < ApplicationController before_filter login_required def new redirect_to some_other_path if @order.is_fre...

How can I find the performance bottlenecks in my Ruby application?

I have written a Ruby application which parses lots of data from sources in different formats html, xml and csv files. How can I find out what areas of the code are taking the longest? Is there any good resources on how to improve the performance of Ruby applications? Or do you have any performance coding standards you always follow? ...

Why is the Rails Inflector module deprecated?

I looked in the Rails docs under inflector and found this message... Module deprecated This module is deprecated on the latest stable version of Rails. The last existing version (v2.1.0) is shown here. There was no explanation or reference to any further detail. I recalled seeing a Rails Trac website. I hunted that down and f...

How can I send a NULL in Ruby Sockets?

I'm working on a socket app in Ruby Shoes, and want to send a message to the server. The server expects the XML message, and then a null (0) character. How can I send that in TCP Sockets in Ruby? Thanks. ...

Can Ruby really have design issues that the design patterns solve?

I recently started digging into design patterns. Generally speaking, I thought the design issues that most of the design patterns solve do not generally occur in Ruby. Most of the design issues were because of datatypes (No dynamic typing and arrays can hold objects belonging to same class at a time etc. and many more.). Being a ruby and...

A pretty GUI for autotest

I was wondering if anyone knows of any nice GUIs for autotest? I already know about all the plugins distributed with autotest (growl, knotify etc.), what I want is a little more. I would like a GUI that displays the total count of failed tests at all times. I would like the GUI to allow me to click through to the failing test (have t...

Type Conversions in Ruby: The "Right" Way?

I am trying to decide if a string is a number in Ruby. This is my code whatAmI = "32.3a22" puts "This is always false " + String(whatAmI.is_a?(Fixnum)); isNum = false; begin Float(whatAmI) isNum = true; rescue Exception => e puts "What does Ruby say? " + e isNum = false; end puts isNum I realize that I can do it with a RegEx, ...