ruby

uninitialized constant Active Scaffold rails 2.3.5

Hi guy, I update my rails application 2.0.2 to 2.3.5. I use active scaffold for the administration part. I change nothing in my code but a problem is coming with the update. I have a controller 'admin/user_controller' to manage users. Here is the code of the controller: class Admin::UserController < ApplicationController layou...

Deploying rails application

Hi, I've been playing around with rails lately and wanted to go through the deploent process just to see how it worked. I created a simple app with a sIngle model from a scaffold. I uploaded it to my server and found I needed to add /public to the URL to get the 'welcome to rails' screen. However, if I attempted to access my model (pu...

Regular Expression Text Selection

I'm working on a website where I have some text which I am using the RedCloth gem to markdown. basically I need to intercept some text before it gets to the gem, and parse the text with a colour code syntax gem. My regex is very poor (and I don't know if I can do this.) I need to select chucks of text and parse them before RedCloth gets ...

Split string in Ruby, ignoring contents of parentheses?

I need to split a string into a list of parts in Ruby, but I need to ignore stuff inside paramentheses. For example: A +4, B +6, C (hello, goodbye) +5, D +3 I'd like the resulting list to be: [0]A +4 [1]B +6 [2]C (hello, goodbye) +5 [3]D +3 But I can't simply split on commas, because that would split the contents of the parentheses...

How to add a form name to a form in ruby?

Hi, How can I add a form name to the following line? <% form_tag({}, :method => :get) do %> ...

Authenticating (setting cookies) on 2 seperate domains

I'd appreciate any thoughts/insight any of you might have on this... I have two domains running the same applications e.g. mysite.com and mysite.org and I have a requirement that when a user logs into mysite.com then he should also be logged into mysite.org. Obviously, I can't set the cookie on another domain but I want to come up with ...

String Comparison in ruby

I am using following code to compare string but its always takes me to else case, why it is so? its always printing else part which is "You have enter wrong abbreviation" print("Enter your state abbreviation: ") state_abbreviation = gets if state_abbreviation.upcase == "NC" puts("North Carolina") elsif state_abbreviation.upcase == "SC...

Rails, jQuery, .js.erb files, JS not executed by the browser.

I'm trying to use jQuery, and everything has been great, until now, when I'm trying to render a partial and append it to a div. Here is how I have it set up: I have an action that responds to js: def index @objects = Object.find(:all) respond_to do |format| format.js end end And a template called index.js.erb with some jav...

How do I interact with a MS Exchange calendar from a Unix command line?

I want to write a bot that will automatically watch a MS exchange account's calendar and accept and log any invitations. The rest of the code will be in Ruby, so I'd prefer that, but I'm happy to use any POSIX tool -- a C program, a Perl script, etc. I've looked around for Unix client information, but all I found were email clients (e.g...

Getting module of caller in Ruby

We have code to log data in our Ruby 1.8.6 web application. You call it roughly as follows: $log.info("Some text here") Now, in the logged output, I would like to include the module where that line appeared. I know that the Kernel#caller will give me an array where I can pull out the file and line number that the log line occurred, ...

How to add span tags to this link type in Ruby?

How can I add span tags to the following link in ruby? <%= link_to l(:label_demo), {:action => 'test', :class => 'link' %> ...

Apache Buildr issue with ant task / Hash.from_java_properties

I have a buildr script that first loads a java properties file, then creates an ant task. I'm getting an abort error: Buildr aborted! org/apache/tools/ant/DefaultLogger when running buildr. Here's the (simplified) buildfile: CONFIG = Hash.from_java_properties("a=1") define "my_project", :version => "1.0" do ant("ant_test") do |ant...

How can I detect if a cookie exists using the Ruby programming language?

I know how to read cookies using CGI and Ruby but the problem is, if I try to read cookies.value[0] when it does not exists, it breaks my program. So I need to check if the cookie is there to read first. I can't find this answer anywhere on the internet. Please help, thank you, Henry. ...

Rails redirect_to "www.somewebsite.com" with GET/POST parameters?

Hi, I'm trying to issue a redirect_to in one of my controllers to a fully qualified URL + I want to pass in some parameters In the controller for site A I do: redirect_to: "www.siteB.com/my_controller/my_action?my_parameter=123" Is there a nicer way to do this in rails? ...

Ruby 1.9.1 or Ruby 1.8.7 Enterprise Edition on a small VM?

Someone posted something similar here, however I'm curious to which would run faster and save me more memory? I know that Matz as made many enhancements in 1.9 but I also stand behind the decisions the Phusion guys have made as well. My question is which is the best to run on my VM which only has 265mb of ram? ...

Simulating race conditions in RSpec unit tests

We have an asynchronous task that performs a potentially long-running calculation for an object. The result is then cached on the object. To prevent multiple tasks from repeating the same work, we added locking with an atomic SQL update: UPDATE objects SET locked = 1 WHERE id = 1234 AND locked = 0 The locking is only for the asynchr...

A Many-Many Association Hidden_Field edit problem. ROR

I'm trying to pass an array into a hidden_field. The following User has 3 roles [2,4,5] >> u = User.find_by_login("lesa") => #<User id: 5, login: "lesa", email: "[email protected]", crypted_password: "0f2776e68f1054a2678ad69a3b28e35ad9f42078", salt: "f02ef9e00d16f1b9f82dfcc488fdf96bf5aab4a8", created_at: "2009-12-29 15:15:51", upd...

what are the major differences and similarity in java and ruby?

Hi I am java professional now I like to go for ruby.Are there any similarity in both the languages? and what are the major differences? As both are object oriented. ...

Where are catch and throw useful in Ruby?

I really don't see a sane use for these. There is already rescue and raise, so why the need for throw and catch? It seems they are supposed to be used to jump out of deep nesting, but that just smells like a goto to me. Are there any examples of good, clean use for these? ...

Regex: don't match if string contains whitespace

I can't seem to figure out the regex pattern for matching strings only if it doesn't contain whitespace. For example "this has whitespace".match(/some_pattern/) should return nil but "nowhitespace".match(/some_pattern/) should return the MatchData with the entire string. Can anyone suggest a solution for the above? ...