ruby-on-rails

Tarantula for rails app

I am just trying to get a simple tarantula request working, but finding it difficult without an api. If I have a simple test like tarantula_crawl(self) I get an error like 1) Error: test_tarantula(TarantulaTest): RuntimeError: 9 failures tarantula (0.3.3) [v] lib/relevance/tarantula/crawler.rb:221:in generate_reports' tarantula ...

Rails: Creating subfolders in model?

I'm going to have a ton of subclasses, so want to organize them under a subfolder called stream. I added the following line to the environment.rb so that all classes in the subfolder would be loaded: Rails::Initializer.run do |config| ... config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File...

Custom Drop Down box in Ruby on Rails with links as a couple of the options.

So...basically, I want this in my drop down: •Nothing •Option 1 •Option 2 •Option 3 Link to another page Link to another page I tried throwing a link_to to a select tag... that didnt work... any ideas? ...

autospec and missing gem

Hi, i've got a strange behavior or autospec. On autospec run i see in console /opt/local/bin/ruby /opt/local/lib/ruby/gems/1.8/gems/cucumber-0.7.3/bin/cucumber --profile autotest-all --format rerun --out /var/folders/xx/xxbiSMYpEjesle1hezvfDU+++TI/-Tmp-/autotest-cucumber20100603-46558-rwbmlp-0 Missing these required gems: cucumber-ra...

Ajax Request using jQuery in Rails

Hi... I am sending an Ajax Request using jQuery. What happens is that I am getting an "405 Method Not Allowed" Error. I am just posting a form, which would get the detail from the form and insert it into the DB. Just the usual stuff.I am using WEBrick that comes as default with the rails package. Can somebody please tell me how to fix th...

Customizing the Stars Image for Ajaxful_Rating RoR plugin

I'm trying to come up with my own star image that's slightly smaller and different style than the one provided in the gem/plugin, but Ajaxful_rating doesn't have an easy way to do this. Here's what I've figured out so far: The stars.png in the public folder is three 25x25 pixel tiles stacked vertically, ordered empty star, normal star...

Rails ActiveRecord friendly code from a Complex Join, Sum, and Group query

PROBLEM Hello, I am having no luck trying to break down this SQL statement into ActiveRecord/Rails friendly code and I'd like to learn how I can avoid a find_by_sql statement in this situation. Scenario I have users that create audits when they perform an action. Each audit is of a specific audit_activity. Each audit_activity is wort...

Has anyone successfully set up their email settings on EngineYard?

I am attempting to add email capabilities to my app (forgotten password, notifications, etc.) and I am using EngineYard for hosting. I have successfully configured email in my test environment but upon uploading to EY it seems to error out in Production. I don't pay for their support and the only resource is a bit vague (or beyond me). ...

:include and table aliasing

I'm suffering from a variant of the problem described here: ActiveRecord assigns table aliases for association joins fairly unpredictably. The first association to a given table keeps the table name. Further joins with associations to that table use aliases including the association names in the path... but it is comm...

Optional mix of filter parameters in a search the Rails way.

I've got a simple list page with a couple of search filters status which is a simple enumeration and a test query which I want to compare against both the title and description field of my model. In my controller, I want to do something like this: def index conditions = {} conditions[:status] = params[:status] if params[:status] an...

How to refactor this Ruby on Rails code?

I want to fetch posts based on their status, so I have this code inside my PostsController index action. It seems to be cluttering the index action, though, and I'm not sure it belongs here. How could I make it more concise and where would I move it in my application so it doesn't clutter up my index action (if that is the correct thing...

expiring image assets referenced from stylesheets

So rails appends timestamps to CSS, JS and image files: image_tag 'foo.png' => <img src="foo.png?123123123123' /> # or somethin like that ...which is really useful for doing far-future expiration, etc. with Apache's help. But what about images referenced from stylesheets? They don't get an appended timestamp. So it seems to me tha...

Using jQuery and Rails to display data on a Google Map

Hi, I'm having trouble getting JSON data from my Rails app to display on a Google Map using jQuery. In my controller: class PlacesController < ApplicationController respond_to :html, :xml, :json # GET /places # GET /places.xml # GET /places.json def index @places = Place.all respond_to do |format| format.html...

Rails — Formtastic, how to set text for options in select?

f.input :some_model_values, :as => :select Using Formtastic, I need to set a text for options on my select input, but not populated from :some_model_values. The second: how could be collection of :some_model_values pre-modefied? Because i don want to show some options according to user role. Thanks! ...

Ruby - Read file in batches

Hi, I am reading a file that is 10mb in size and which contains some id's. I read them into a list in ruby. I am concerned that it might cause memory issues in the future, when the number of id's in file might increase. Is there a effective way of reading a large file in batches? Thank you ...

Rails SQL injection?

In Rails, when I want to find by a user given value and avoid SQL injection (escape apostrophes and the like) I can do something like this: Post.all(:conditions => ['title = ?', params[:title]]) I know that an unsafe way of doing this (possible SQL injection) is this: Post.all(:conditions => "title = #{params[:title]}") My question...

Using non-Railsy route to prepopulate a form

I have many instances of a Rails model, Post. When viewing an individual post, I'd like to create a form to create a child of Post called Comment. I'd like to prepopulate this form with a hidden tag that contains the post_id which is the foreign key in Comment. The Railsy way to do this is to create a fancy-ish route such as: /comment...

Rails, destroy if blank

This might sound odd, but is there a 'Rails way' to have a model destroyed if a certain attribute is blank? Say I have a model like tags with just a name attribute or something, if the user edits the tag and deletes all the text out of the name field in the form I'd like the model to just be deleted. I'm aware of the reject_if method, b...

Regular expression in Ruby

Hi, Could anybody help me make a proper regular expression from a bunch of text in Ruby. I tried a lot but I don't know how to handle variable length titles. The string will be of format <sometext>title:"<actual_title>"<sometext>. I want to extract actual_title from this string. I tried /title:"."/ but it doesnt find any matches as it...

How to test the XML sent to a web service in Ruby/Rails

I'm looking for the best way to write unit test for code that POSTs to an external web service. The body of the POST request is an XML document which describes the actions and data for the web service to perform. Now, I've wrapped the webservice in its own class (similar to ActiveResource), and I can't see any way to test the exact XML ...