ruby-on-rails

Shoulda on Rails - should render_with_layout deferred

Hi all, I would appreciate if someone could help/explain the following please. I am trying to test a controller with shoulda to see if a correct layout is used. The method should_render_with_layout throws a NoMethodError whilst should render_with_layout passes but says the function is deferred. Any help would be appreciated.. Thanks ...

undefined method sitenum

Hey all, I get a sitenum undefined method error. Problem is I am trying to target site_id and student_number and then increment value of student_number by 1 based on site_id. So there will be at least two records with a 2001 value for student_number if there are two site_ids (e.g. site_id 1, site_id 2). And if a value of 2001 exists for ...

How do you programmatically inspect the sql generated by active record

What's the code to look at the sql an ActiveRecord query is going to produce. For example, Modelname.all would produce "Select * from modelname". Is there any method that gives access to that string? ...

Authlogic: logging-in twice on the same test

Is there any way to logout and login another user when testing with Authlogic? The following test case just fails class MessagesControllerTest < ActionController::TestCase setup :activate_authlogic should "sender send a message and recipient delete it" do @sender = Factory(:user, :login => 'sender') @recipient = Factory(:u...

Get all models having implemented a certain method

I have many models created with the standard rails model generator. Some of the models have then got a method called foo(). Is there a simple way to figure out all the class names of the generated models having the foo() method implemented ? I mean programmaticaly, from a rails controller, not from the console grepping the sourcecode....

Ruby on Rails -Problem using subdirectories

Hi, I have tried to set up a separate section of my app using a subdirectory called controlpanel to manage various parts of the site. I've set up the namespace in my routes.rb map.namespace :controlpanel do |submap| submap.resources :pages # other controllers end And placed the controller and views into the relevant subdirect...

Call Application Controller functions from Rake task

Hi, I want to call a function in my ApplicationController from a rake task. I've added the => :environment tag, but it just doesn't want to work. Here is my stripped down code- lib\taks\autoscrape.rake: desc "This task will scrape all the movies without info" task(:autoscrape => :environment) do require 'application' #probably ...

Ruby or Python ?

I want to write software for the iPod/iPad. I find Objective-C difficult to learn. Between Ruby and Python, which one is best suited for writing software for iPod/iPad? Please advise which tutorial book for the best one? ...

Is there a way to make ActiveRecord write 'WHERE (a,b) in ((1,2),(3,4))' using AR finders.

Is there a way to make ActiveRecord write 'WHERE (a,b) in ((1,2),(3,4))' using AR finders. I would think Widget.find(:all, :conditions => ['(a,b) in (?)', [[1,2][3,4]]]) but the inner arrays get converted to YAML?!?! Right now I'm using find_by_sql. Is there a better way to write this? ...

cache.fetch in Django?

Does Django caching have a method similar to Rails' cache.fetch? (http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#M001023) The rails cache fetch works like: cache.fetch("my_key") { // return what I want to put in my_key if it is empty "some_value" } It's useful because it checks the cache, and returns the value ...

Rails Paperclip plugin - Validations

The rails plugin paperclip supports validations at the model such as: validates_attachment_size The only problem is that using this validation seems to force the validation of an actual attachment, where sometimes there may not be one. If I'm validating the following, what condition :if could I use to ignore the validation if there i...

Why does Model.find behaviour in a deployed environment differ from that in a development enviroment?

Using Ruby on Rails combined with capistrano and git, I've run into an annoying problem.. I have a controller "people" with the index action that looks something like this: def index @people = Person.find( :conditions => params[:search] ) end There is a boolean "is_admin" column in the Person table. Assuming that some of the peopl...

Multiple forms for the same model in a single page

On the front page of my rap lyrics explanation site, there's a place where users can try explaining a challenging line: Here's the partial I use to generate this: <div class="stand_alone annotation" data-id="<%= annotation.id %>"> <%= song_link(annotation.song, :class => :title) %> <span class="needs_exegesis"><%= annotation.ref...

Flash not surviving a redirect in Facebook on a Rails application

I have the following two action methods: def index puts "==index== flash: #{flash.inspect}" end def create flash[:notice] = "Blah" puts "==create== flash: #{flash.inspect}" redirect_to(:action => :index) end index.fbml.erb contains this: <%= button_to_with_facebooker "Blah!", :action => :create %> The application is used t...

Rails validates_uniqueness_of across multiple columns with case insensitivity

I have a model that has two fields, which I will call first_name and last_name, and I want to make sure that the combination of the two are case-insensitively unique. I've gotten halfway there by using this: validates_uniqueness_of :first_name, :scope => :last_name The problem is that the uniqueness check seems to be case sensitive, e...

Rails Hash with several object attributes. How do I save them all?

I get hash from a fields_for that looks like this: "affiliation_attributes"=>{ "11"=>{"volunteer_id"=>"14", "affiliationtype_id"=>"1", "organization_id"=>"1"}, "1"=>{"volunteer_id"=>"1", "affiliationtype_id"=>"3", "organization_id"=>"1"}, "4"=>{"volunteer_id"=>"2", "affiliationtype_id"=>"3", "organization_id"=>"1"}, "21"=>{"volunte...

User selected CSS stylesheet in Rails

I'm working on a site in Rails and I'd like for the user to be able to change the CSS stylesheet to either a light or dark theme. I have this in my view so that I can use a variable for the stylesheet: <%= stylesheet_link_tag @current_stylesheet %> I tried to change that variable by having a link in my view something like this: <%...

Learning 'advanced' ruby to contribute to rails?

What is the best place to learn 'advanced' Ruby so I can start contributing to Rails? Any other things I should read/know would be appreciated. Thanks. ...

Printing to screen in a rake task

I have a long running rake task. Every now and then I print an update to the screen to let me know how far along the task has come. puts "Almost there..." My problem is all the puts statements seem to buffer somewhere and won't print to the screen until after the task is complete. At which point, they will be printed all at once. Is ...

ruby on rails vs codeigniter

hi all... between ruby on rails and codeigniter, which framework is better (and why) for a website with user management profile pages subscriptions blog upload/download ...