ruby-on-rails

How do I properly setup transactional fixtures in Rails?

I just started a new project yesterday and I'm having a lot of very strange transactional fixture problems. It sounds like this is something of an issue with Rails, so I'm hoping StackOverflow can help. Here's the rundown. Coworkers can run tests fine. They are running Mac OS X; I'm running Ubuntu. When use_transactional_fixtures is tr...

How to validate that zip code enter by user is correct US zipcode

I want to validate that zip code entered by user is valid or not. for example user entered 009876654 and it is not valid then an error message should be given. I know i can do it using javascript regulr expression or using ajax-zip-code-database But i don't want any of the above. i need some plugin sort of thing which send request t...

Why is stubbing not working correctly in Ruby Double (rr)?

I have a simple spec test in my Ruby on Rails application: stub.instance_of(Search).x { 3 } puts Search.new.x # displays 3 puts Search.first.x # gives me an error: undefined method `x' for #<Search:0xb5fabaa8> why does the third line fail? Search.first does return an instance of Search. Thanks ...

Rails Form with checkboxes

I have two models, Leads and courses, Leads HABTM courses. I want to list all courses in leads/new as checkboxes, at the moment I have them as a multiselect box, but I dont like the way it works. This is what I have at the moment <%= f.collection_select :course_ids, Course.find(:all, :order => 'course_type'), :id, :course_name, {},...

Unknown Method key? error in Rails 2.3.8 Unit testing

I was writing unit tests for my models for a while. After that I was tweaking around and again continued writing unit tests. Earlier all my unit tests were working - successfully. But now WHen I run them, it gives me Loaded suite unit/post_test Started EEEE Finished in 0.112698 seconds. 1) Error: test_presence_of_body(PostTest): No...

Boolean model attributes as automatic methods

I'm working through http://railstutorial.org (currently working on section 10.4.2 - destroying users). My User model has a boolean admin attribute, and in the Users controller there is some simple code making use of this attribute: def admin_user redirect_to(root_path) unless current_user.admin? end The RSpec test: describe "as a ...

Update object array values in rails view.

I have @table_name(object array) contain many objects. I want to replace its column values one by one with my values.. i have use <% for group_permission in @table_name %> <%end%> How i change Please help me ...

How to load jQuery dynamically with Rails?

I have a page, where I load a partial (that contains a form) dynamically. So after that you click in a button, via jQuery I do a get, get the form and I change the html of a div. Everything works great. The problem is I have some javascript that I added inline on the partial and I would like to remove it. So in my partial I made some...

Automatically deleting objects older than n days in Amazon S3 (How ?)

I am storing many images in Amazon S3, using a ruby lib (http://amazon.rubyforge.org/) I don't care the photos older than 1 week, then to free the space in S3 I have to delete those photos. I know there is a method to delete the object in a certain bucket: S3Object.delete 'photo-1.jpg', 'photos' Is there a way to automatically delet...

Ruby on Rails: formatting date inside a field

My field: <%= f.text_field :expires_at, :label => false, :class => "input-field" %> but I want the date to be kinda like this when the page loads: June, 1st, 1752 9:54:00 pm How would I do that? ...

rubyon rails, rake, crontab and encoding

I have a rails rake task which runs just fine. I want this task to be run periodically by crontab so I added it to crontab as follows : 0,30,0 * * * * cd /var/www/html/metajorn && RAILS_ENV=production /usr/local/bin/rake myraketask --trace >> /var/www/html/metajorn/log/cron_log.log 2>&1 In cron_log.log I'm seeing the following error...

Rails Workflow::create_workflow_diagram options

What are all the options available for the command: Workflow::create_workflow_diagram(klass, dir, opts) and how shall I specify them on Ruby code? I've already found this on graphviz options, but I don't know how to use these options on Ruby code... Thank you all! ...

disable character escaping in to_json / Hash.from_xml

I try to implement an api for a projekt and found this article http://www.coffeepowered.net/2009/02/16/powerful-easy-dry-multi-format-rest-apis-part-2/ So i get a xml.builder template to build my response and render it to json. It works great, but I have some utf-8 encoded Data I want to respond. First I specify the xml encoding. Next...

How to determine the time taken to complete a Rails query

I would like to include query statistics (i.e. records returned and elapsed time) in my Index views (similar to Google's). I found the records returned, but am having difficultly locating the elapsed time. I'm using Rails3 beta and the will_paginate plugin. ...

link_to div with Ruby on Rails

How would i use <% link_to (post) do %> <%= pluralize(post.comments.size,'comment') %> <% end %> to link to a div, for example the url: http://myblog.com/post/21#mydiv i need to do this so that when a user clicks the comments link they are taken to the comments div on the page. This would also be useful to use to redirect us...

Ruby on Rails: insert javascript into a page

So.. I have this in the action called when someone clicks the archive button respond_to do |format| format.js do render :update do |page| page << "alert('You have reached your archive object limit. You have #{remaining} remaining archived objects.');" end end end But instead of alerting, it just gets rid of the ...

Rails: Manipulating params before saving an update - wrong approach?

First, I feel like I am approaching this the wrong way, but I'm not sure how else to do it. It's somewhat difficult to explain as well, so please bear with me. I am using Javascript to allow users to add multiple text areas in the edit form, but these text areas are for a separate model. It basically allows the user to edit the inform...

Ruby on Rails registration data?

Hi, I am trying to build a registration page, with two steps. The first step displays a form with name, email, pass. The second step will display a ReCaptcha. The problem is how do I store the form data and display a new form with a captcha? I was thinking sessions, but I know you're not supposed to store sensitive information in se...

MySQL + Snow Leopard + 32 Bit + Ruby on Rails = uninitialized constant MysqlCompat::MysqlRes (HELP!)

So i'm running Snow Leopard on a BlackBook. I'm attempting to get rake db:migrate to work with this project but I get the MysqlCompat::MysqlRes error. Is there any special way to install or build the gem and/or the actual MySQL binaries themselves to get this to work on my machine? ...

Rails questions, SQL statement in logs

So I am new to Rails, so pardon the basic question. I see rails spits this out (in the console) for every request I make to my controller. Why? I'm not even doing any DB operation, I just started writing a HelloWorld rails app. I did pick mysql as the db when creating this rails project (rails -d mysql helloworld) SQL (0.1ms) SET NA...