ruby-on-rails

Getting the full RSpec test name from within a before(:each) block

RSpec allows you to get the current running test method name in a before(:each) block, by doing the following: Spec::Runner.configure do |config| config.before :each do |x| x.method_name # returns 'should be cool' end end This is for a test like: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe '...

Ruby Version Discrepancy when running server

$ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.3.0] $ rails s => Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-09-28 13:45:50] INFO WEBrick 1.3.1 [2010-09-28 13:45:50] INFO ruby 1.8.7 (2009-06-08) [universal-dar...

Problems with using the jQuery watermark and rails validations...

Ok so i have a text field that uses this jQuery watermark plugin which is really easy to implement. The problem comes into play when i need to validate this field with a rails validation. For example.. def validate errors.add(:price, "should be at least $0.01") if price < 0.01 end I am using the plugin like this $("#request_pric...

how to use memcache to speed-up rails/heroku

Heroku supports memcache natively as an addon. my problem is, being a rails newbie still, I have no clue how to use memcache in order to speed-up my most time-consuming request (I know which they are by looking a the newrelic analysis). should we use a gem like 'cache-money' on-top of memcache? does anyone use act_as_cached anymore? I k...

Rails 2.3.8 application not booting after installing RVM...

After installing Rails 3, RVM and Ruby 1.9.2, I've been having trouble running this Rails 2.3.8 app. necromancer@factory$ script/server ./script/../config/boot.rb:5: uninitialized constant Rails (NameError) from script/server:2:in `require' from script/server:2 After running gem which rails, I got the following path: /Users/necrom...

Several rails model references on one table

Hello, I am quite new to ruby on rails, but I find it phantastic. Anyway, I am currently building my model-set, so to speak. I have a model Places, generated like this: rails generate scaffold Place name:string description:text type:string Now I want to make a model Route between two places, holding a distance. How can I do that, I o...

Using a normal text link instead of a form. Please help!

Hello! I am writing a small application using Rails 3. In one part of it there is a link (should be a link) that if clicked adds a connection between two people (see below). What I am really needing is to use a normal text link instead of a form, how is this done? <%= form_for([@profile, @contact]) do |f| %> <p><%= f.hidden_field...

same code in different actions of the controller in rails -- how to make DRY?

I have a controller with two different actions, but both need this same code, which is a little long, how can I allow them access to this same behavior but keep it DRY? @list = Contact.find :all, :select => "companies.name AS co_name, companies.id AS comp_id, COUNT(contact_emails.id) AS ema...

Change CSS width using javascript (JQuery Tools Scrollable) center

I am using JQuery Tools Scrollable to build a full-page-width scrollable form, such that each page of the form scrolls all the way across the page, replaced by the next page sliding in from the right. The problem I'm having is how to center each page such that it stays centered amidst browser resizing and in-browser zooming (Ctrl +/-). ...

How to move your rake tasks to the rails lib dir from in a gem generator?

Im creating a custom gem and have some rake files that need to be installed into the users /lib/tasks directory to work. I want create a generator that will move / create my rake tasks in the tasks directory so they can use them. Does anyone have any idea how do to this in a custom gem? ...

How to generate and link to an arbitrary file?

Here's what I'm trying to do. Let's say the user is looking at the foo view for the foo action of the bar controller, and I've got a variable called @userName. bar_controller.rb class BarController def foo @userName = getUserName(); end foo.html.erb Hi mom! I want to create a filed called <%= @userName %>.myExt with the i...

Where is Ruby being told to display this information?

Brief question, beginner's work on Ruby/Rails. Here's my view: <h1>News</h1> <%= @posts.each do |post| %> <h1><%= post.title %></h1> <p><strong>By:</strong> <%= post.name %></p> <p><%= post.content %></p> <p><%= link_to 'Read More', post %> | <%= link_to 'Edit', edit_post_path(post) %> | <%= link_to 'Destroy', post, :confirm => 'A...

Use db:migrate:redo while properly handling exceptions from schema changes

I have a migration that's breaking in the middle of a couple of schema changes. When it breaks an exception is thrown and rake db:migrate exits, leaving my database in a half-migrated state. How can I set it up so that the migration automatically reverts just the changes that have run so far? I'd like to do so globally when in developm...

Ruby on Rails cPanel Mongrel config

Hi All, I've setup my rails app in ~/rails_apps/testapp. I've got it running on port 12004 (there are some issues with mongrel, but i've got it running now so that's sorted i believe). I've set up the following in my ~/public_html/.htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} ^mysite.com.au$ [OR] RewriteCond %{HTTP_HOST} ...

Accessing object of form in formtastic

So I'm making a survey app. The users choose a type of form on the backend, and it displays as a certain type on the front end. That's only ideally, of course. What happens now is I can't access the object formtastic is building the form for. How can I say something like "question.kind"? It just makes an error that way. Here's what I hav...

Modifying devise modules after first generation

Hi, I'm in the process of learning rails. I've found Devise to be great with getting authentication up and running quickly and seamlessly but I do have one question. How do I change the modules after the first run of the Devise generator (e.g. rails g devise User)? This defaults with the following migration: def self.up create_tab...

Testing Rails+Webhooks with Cucumber

I'm trying to integrate my rails application with an external service. I'm using Cucumber to do integration testing and I'd don't want to mock out the external service at times. When I get webhooks from this service, they are routed to apache running my development environment. This would be easy to fix if I could figure out how to fi...

Why does RubyGems FasterCSV process [[1,3,5], [2,4,6]].to_csv as "135,246\n"

the following code: [1,3,5].to_csv => "1,3,5\n" # this is good [[1,3,5], [2,4,6]].to_csv => "135,246\n" # why doesn't it just do it for array of array? but require this instead: data = [[1,3,5], [2,4,6]] csv_string = FasterCSV.generate do |csv| data.each {|a| csv << a} end => "1,3,5\n2,4,6\n" or shorter: data =...

JQuery UI - How do you do multiple toggles from a listBox?

I have a listbox in a form, and based on the answers within I want to open a different toggle, using JQuery UI's toggle effect: http://jqueryui.com/demos/toggle/. The code is visible under 'view source'. Part 1: the code in current form does not support multiple toggles on one page. How can I rewrite the javascript and id the divs diffe...

How do I convert a time to users time zone in Rails

I set the local timezone in Rails with this javascript function in my layout: <script type="text/javascript" charset="utf-8"> <% unless session[:timezone_offset] %> $.ajax({ url: '/main/timezone', type: 'GET', data: { offset: (new Date()).getTimezoneOffset() } }); ...