ruby-on-rails

Is there built in support in rails for the default value substitution idiom?

I often write code to provide a default value upon encountering nil/empty value. E.g: category = order.category || "Any" # OR category = order.category.empty? ? "Any" : order.category I am about to extend the try method to handle this idiom. category = order.try(:category, :on_nill => "Any") # OR category = order.try(:category, :o...

Rails ActiveRecord Question

Single Table Inheritance using ActiveRecord. Since we can use @test = Employee.all and find all the employees created. How does rails do this? Since we only use a User Table. How does it know about employees and retrieve only employees? Rails Magic? Explanation anyone? Thank you in advance. Base Class : Person (inherits ActiveRecord) Su...

binding jquery ui methods after ajax calls

I am using jquery ui in several places to create ui elements like tabs, tooltips etc. These all follow the same format of $('selector').ui_method_name, where the ui-method-name could be tabs, accordion, tooltip etc. This all works fine when the page loads first and this line is called on $(document).ready, but in some cases I load conte...

rails 3 named routes

I am upgrading my application to rails 3. My old route was map.profile 'profile/:login', :controller => 'profile', :action => 'show' I changed this to: match 'profile/:login', :to => 'profile#show' This works when I enter in the route say /profile/red99 But when I use a generic link like: <%= link_to image.user.login, :contro...

How can I test streamed data with Webrat?

I have code for streaming a CSV similar to the following in a controller: def download filename = 'data.csv' headers.merge!( 'Content-Type' => 'text/csv', 'Content-Disposition' => "attachment; filename=\"#{filename}\"", 'Content-Transfer-Encoding' => 'binary') render :status => 200, :text => Proc.new { |response, outp...

Why do Ruby's regular expressions use \A and \z instead of ^ and $?

Hello all, I'm not a Ruby programmer, but as I was reading through the extensive RoR security guide I noticed this section: http://guides.rubyonrails.org/security.html#regular-expressions A common pitfall in Ruby’s regular expressions is to match the string’s beginning and end by ^ and $, instead of \A and \z. Does anyone know if...

What is the fastest way to calculate disk usage per customer?

Hi there, I'm hoping this is a simple one. I run a Rails web app where I'm hosting about 100 school websites. The one app handles all the sites, and I have a management interface where we can add and remove schools etc... I want to add a stat to this interface which is the total disk space used by that school. Each schools files are st...

Is Rails's "delayed_job" for cron task really?

delayed_job is at http://github.com/collectiveidea/delayed_job Can delayed_job have the ability to do cron task? Such as running a script every night at 1am. Or run a script every 1 hour. If not, what are the suitable gems that can do that? And can it be monitored remotely using a browser, and have logging of success and error? ...

rjb ruby 1.9.1, different behavior in script/server vs script/console

Running into weird errors with Rjb when ran from script/server (using stanfordparser, if that makes a difference): Test code: Rjb::load("/usr/local/stanford-parser/current/stanford-parser.jar") In controller: def test Rjb::load("/usr/local/stanford-parser/current/stanford-parser.jar") render :text => "OK" end When ran from scr...

Ruby on Rails: Unable to assign attributes to models built in unit tests

I'm trying to test creation of a new model inside my unit tests, and I'm getting some puzzling behavior. In this example, I already have a fixture that define an Article :valid_article: public_review = Review.new({:article => articles(:valid_article)}) assert !public_review.article_id.nil? Oddly enough, this fails the assertion, beca...

Nested rails form without accepts_nested_attributes_for

I am update a clients rails application and its rails RAILS_GEM_VERSION = '2.2.2' and I need a nested form...any suggestions of another idea I have user which has one profile ...

rescue_from NoMethodError

Having problems figuring this out. trying to do a rescue_from NoMethodError, :with => :try_some_options But its not working. EDITED: For testing I'm doing a simple redirect def try_some_options redirect_to root_url end EDITED 2: Sample of my controller. Added (exception) as recommended below. I know the reason I'm getting the...

RoR field set on form_for

Hi, How do you add a field set to a form_for method? ...

Sunspot not indexing model after save

I have a model which deploys a delayed job that updates some of its attributes. The model is declared "searchable"... searchable do text :content, :stored => true end ... which I thought would re-index after a save. On testing, this doesn't seem to be the case. If I run: rake sunspot:reindex, then everything works as expected. ...

Which is better for database design, RoR or PHP?

I am about to embark on a project which will be a database with potentially thousands of entries. It is for an Australian audience so load should not be particularly high. The developer who is interested has a strong preference for RoR. However I am unconvinced of the benefits of RoR for all aspects of a project. For example, while RoR...

TypeError: can't convert Post into Array

I'm using Rails 3 and will_paginate. Pagination works fine in my Posts controller but in my Tags controller I get an error on the second Tag id. Here's the error: TypeError in TagsController#show can't convert Post into Array ... app/controllers/tags_controller.rb:8:in `show' tags_controller.rb#show: def show @tag = ActsAsTaggab...

Get HTTP response Using Shoulda Ruby on Rails

I'm migrating over to shoulda from rspec and I can't seem to get access to the http response. Can someone point out what I may be doing wrong? context "doing somethin" do setup do get :index end @response.body should respond_with :success end When i run this i get an error saying that @response is a...

Rails Text_area_tag problem

I am trying to resize my text area tag though when I try to make the adjustments nothing happens to the box itself. I have tried: <%= text_area_tag :reason, :nil, :size=> "44x6" %> <%= text_area_tag :reason, :nil, :cols=>20,:rows=>5 %> Any ideas? Thanks. ...

Issues with Relationships

You can take a look at the app I'm referring to at: http://github.com/585connor/QA So, I've built this question & answer app... kind of. I can get the answers to be listed on their respective questions but I cannot figure out how to get the user info to be displayed on those questions/answers. For example I'd like to put the username ne...

Rails Best Practices for RESTful controller CREATE and UPDATE methods

OK, I am trying to understand the best practices for the CREATE and UPDATE methods for both HTML and XML formats. The default code for a controller that the rails generator generates is a little unclear to me. For the CREATE method, given a good save, the generator says to "redirect_to(@whatever)" for HTML and "render :xml => @whatever...