ruby

Rails - render :action to target anchor tag?

I'm looking to use render like so: render :action => 'page#form' I also tried this: render :template => 'site/page#form' That didn't work either. The form on this particular page is at the very bottom, and if any errors occur on submission I'd hate for the user to be defaulted to the top of the page. I also need to use render (not ...

Rails ajax background requests

I have a remote_form which works 100% When a user clicks submit, it goes out grabs so data from the db or data scraped from another website, and updates the page seamlessly... The problem I'm having now, is that I'd like to do the same thing, but do it without having the user click the submit button with an onload event. I think I'm ...

I can't make questions_answers_foo plugin work

Hi, I've downloaded the questions_answers_foo plugin and placed it at vendor->plugins folder, as I usually do. Then, following its documentation, I ran rake question_answers:install and I get this in the output: ArgumentError: wrong # of arguments(0 for 1) I followed the installation steps but I get this error. Does anybody kno...

Loading ruby source from a zip archive?

I have a mod_rails server where disk space, oddly enough, is at a premium. Is there a way for me to compress my application's source, like Python's zipimport? There are obvious disadvantages to this, so I should probably just break down and spend a nickel on disk space, but I figured it'd be worth a shot. ...

How do I create default values in a Ruby Form?

This might be a really basic question but how do I create default values in forms? I'm trying to put the <%= params[:id] %> of the page in as a default hidden value in this form. `<% form_for(@revision) do |f| %> <%= f.error_messages %> <%= f.label :background_title %><br /> <%= f.text_field :background_title %><%= params[:id] %> <...

How to return boolean result in named_scope?

named_scope :incomplete?, lambda { |user_id, todo_id| { :select => 1, :conditions => [ "#{user_id} not in (select user_todos.user_id from user_todos) and #{todo_id} not in (select user_todos.todo_id from user_todos)" ] } } I'm getting a nil result. I want it to return true. What I gotta do!? Also, is there a better w...

How to output my ruby commandline text in different colours

How can I make the puts commands I output from a commandline based ruby program colour? I would appreciated any references to how I call each different colour also. Lets say we start with this.. Puts "The following word is blue.. Im Blue!" Puts "The following word is green.. Im Green!" Puts "The following word is red.. Im Red!" And I...

Rails - How can I test in IE while developing under Mac OS X?

I've got my Rails application on Mac OS X and it's ready for IE compatibility testing. I've tried running the server and booting up VMware and pulling up the localhost:3000 with no luck. How can I test my Rails application on IE6-8 and Chrome without deploying it somewhere? ...

Is there a reason that we cannot iterate on "reverse Range" in ruby?

I tried to iterate backwards with ruby using a Range and each. This way: (4..0).each do |i| puts i end ==> 4..0 Iteration through 0..4 writes the numbers. On the other Range r = 4..0 seems to be ok, r.first == 4, r.last == 0. Seems to be strange to me that the construct above does not produce the expected result. What is the a reaso...

Rake test loader - load error

Hi, I am a new with ruby. I am trying to run rake test from the application root and I get loaderror, no such file to load from the rake test loader : 5, i.e. it is not able to locate or load the test files. I created a new app to see if this behaviour is app. related, but it still doesn't work. Where should I look? Is this related ...

How to map a full domain to a subdomain-based Rails app account?

I'm developing a Rails app that by default sets up user accounts to a subdomain of their choosing. As an option, they will be able to map their own full domain to their account. So far this is how I have things set up. I am using subdomain-fu to power the routing: # routes.rb map.with_options :conditions => {:subdomain => true} do |app...

Open source Ruby projects - Where to begin?

Hi, I am fairly new to the programming world (about a year) and have done some development in Rails, Ruby, JavaScript in past one year. Over this period I've found out that it "really" gives me joy to program on challenging problems and now I would "really" like to give back to the open source community for all that I've got in past on...

Escaping a Ruby String for TextMate's $DIALOG command

Calling regex gurus. I'm having some trouble right now with escaping a string in Ruby so that I can pass it into a command line utility using exec, %x{} or similar. The command line command is the TextMate dialog feature, which basically works like this (Run this as a shell script in TextMate.): $DIALOG -mp "items=('string1','string2', ...

When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying

A colleague of mine is currently designing SQL queries like the one below to produce reports, which are displayed in excel files through an external data query. At present, only reporting processes on the DB are required (no CRUD operations). I am trying to convince him that it would be better to use a ruby ORM in order to be able to di...

How to add conditions to thinking-sphinx search?

Hi, I've recently installed thinking-sphinx on my ruby on rails app. As first sight, everything works great, I can search words and it will find them. Now, when I try to add some filters(such as, for example, provinces, categories, etc) using: MyModel.search 'hello' :conditions => 'category_id=1' for example, it will throw me the foll...

What do you use Sinatra for?

Im confused about Sinatra (the ruby framework). Is it a lightweight Rails replacement or you can have them running side by side? Can you do a web application (as in Rails)? For example a twitter clone? ...

How does << differ from +?

I see a lot of this sort of this going on in Ruby: myString = "Hello " << "there!" How is this different from doing myString = "Hello " + "there!" ...

Heroku in real life apps

What is your experience using Ruby on Rails on Heroku in production mode? Apart of the issue of the expensive https, do you see any drawback in the way it manages processes, memory and storage? The people at Heroku is quite nice and I'm sure they are willing to answer my questions, but I would like some opinions in the customer side. ...

Does MongoMapper (or any other Mongodb adapter) have a method like "accepts_nested_attributes_for"?

Hi there, I'm considering using mongodb on a new project, but before delving in, I'd like to know if it supports some key features. I know you don't need migrations, and you can add embedded objects,...but does all that mean it also behaves as if the 'accepts_nested_attributes_for' method is always there? Do you know of any other killer...

parse 'page 1 of x' - the best method (ruby/mechanize/nokogiri)

what is the best method using ruby/mechanize/nokogiri to go/click through all pages in case there is more than 1 page I need to access/click on? For example here Page 1 of 34 Should I click the page number or next? Or is out there any better solution? ...