ruby-on-rails

Are Ruby formatted strings and interpolated strings identical in behaviour?

Do the following two lines of code behave in exactly the same way despite slightly different implementations values.map{ |k,v| __send__('%s=' % k.to_s, v) } values.map{ |k,v| __send__("#{k.to_s}=", v) } The second line would be a more common ruby idiom so I was wondering why the other method was used when this was in the Rails Core wh...

Image selector/picker

Using Ruby on Rails what steps can I take to create a image picker. This is a image object which I can use all over my app: Using paperclip and a polymathic association making images available to all other models. I wish to list the images in each model and chose which of them is associated to a individual new or old record. for exampl...

Rails: how does background file upload work?

Uploading a file in a REQUEST/RESPONSE cycle for large files is not a nice experiences for the user, because the application seems to hang during the file upload. Even more critical is that the user can abort the upload, and need to re-start the upload process later. How can I do the upload process in the background? There are some exa...

Perform SUM calculations in ruby on rails xml builder template file

Hello I have an html table which presents working hours for projects In the past 2 days I was trying to export this table to excel file. Finally i was able to do this by using an xml builder template. Here is my file xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.Workbook({ 'xmlns' => "urn:schemas-microsoft-com:o...

Calling data from different model in Rails

Hi Everyone, I need to be able to call data from a different model - not just one field, but any of them. At the moment I have the following models: kase person company party I can call information from the company to the kase and from the person to the kase using this: <li>Client Company Address: <span class="address"><%=h @kase.c...

Cake PHP Routing issue

Hi, I need to do some special routing in cake, but can't for the life of me figure it out. I have a shop controller at /shop, the format of the url will be: /shop/:category/:sub_category/:product_slug In the routing I need to send each part of the url to a different action, for example if the url was just /shop/cakes it would go to t...

functional test for rails controller private method

I have a private method in my controller. which is used for some database update. this method i am calling from another controller method. and it works fine. But when i am trying to write a test case for that method then It is tripping on accessing (session variable and params) in my functional all other methods are working fine the pro...

Exclude draft articles from Solr index with Sunspot

I have an indexed model called Article and I don't want solr to index unpublished articles. class Article < ActiveRecord::Base searchable do text :title text :body end end How can I specify that article that is not #published? should not be indexed? ...

Authentication Problem - not recognizing 'else' - Ruby on rails...

I can't seem to figure out what I am doing wrong here. I have implemented the Super Simple Authentication from Ryan Bates tutorial and while the login portion is functioning correctly, I can't get an error message and redirect to happen correctly for a bad login. Ryan Bates admits in his comments he left this out but can't seem to imple...

undefined method `build_users' with nested models

I've got into trouble with nested attributes. Here is my Account model : class Account < ActiveRecord::Base has_many :products has_many :blogs has_many :openings has_many :users has_one :logo, :class_name => "AccountPicture" has_one :address, :class_name => "AccountAddress" has_and_belongs_to_many :options...

[Rails] How to use form_tag to update params

Dear colleagues, I have been struggling with a problem in Rails for a couple of days and still could not find the solution. Could you help me with that? Problem: I have a search box that puts a :search_string entry in the params structure. I use a form_tag for that and it works fine. <% form_tag :controller=> 'items', :action => 'find...

Rails validates_length_of is misbehaving

Hi I have a rails model that I am adding validations to and I seem to have run into a bit of weirdness from one of the validators. So here is the table I am working with (From schema.rb): create_table "clients", :force => true do |t| t.string "name" t.string "last_contact" t.integer "contacting_agent" t.date ...

Rails + RSpec problem

I have just installed Rspec and Rspec-rails. When i try to run the test, it says: rake aborted! Command /opt/local/bin/ruby -I"lib" "/opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec" "spec/controllers/free_controller_spec.rb" --options "/Volumes/Trash/dev/app/trunk/spec/spec.opts" failed Full log here: http://pastie.org/939211 ...

Ruby on Rails - f.error_messages not showing up

Hi, I've read many posts about this issue but I never got this to work. My model looks like this: class Announcement < ActiveRecord::Base validates_presence_of :title, :description end My controller's create method(only its relevant part) looks like this: def create respond_to do |format| if @announcement.save ...

Action Mailer Confirmation Emails - Ruby on Rails...

I have successfully installed the Clearance Gem from ThoughtBot. Clearance sends a confirmation email upon a new sign_up and suggests adding: config.action_mailer.default_url_options = { :host => 'localhost:3000' } to your /environments/test.rb and development.rb. I have tried this and also config.action_mailer.default_url_options =...

google search as an rss feed

Hi guys, Is there a way to have treat google serach results as an rss feed? For example say I worked for stackoverflow and wanted to montior how if the results from the following search url: http://www.google.com/search?hl=en&amp;q=stackoverflow changes from day today. It would be cool if I could append &output=rss to the url and get ...

Helping Rails Newbies identify version-specific information on web pages

I am trying to help some people getting started programming on rails identify which version that advice found on web pages corresponds to, and am seeking advice and/or guides on how to do it so they don't have to rely on me and/or waste time trying outdated advice. Narrative: I am helping some people get up to speed on rails developmen...

Rails: How do I run a before_save only if certain conditions are met?

I have a before_save method that I call that renames an uploaded image. before_save :randomize_file_name def randomize_file_name extension = File.extname(screen_file_name).downcase key = ActiveSupport::SecureRandom.hex(8) self.screen.instance_write(:file_name, "#{key}#{extension}") end That method is part of my Item model. Tha...

Upgrade rails app from 2.2.2 to 2.3.5

Hi Everyone, How hard/complex would upgrading an application from Rails 2.2.2 to the latest build? I have seen some rake tasks for upgrading from 1.2 versions etc. but havent seen any comments on a smaller increment upgrade. Thanks, Danny Error after upgrade macbook:trunk danny$ script/server => Booting Mongrel => Rails 2.3.5 appl...

Ajax, Multiple Attachments and Paperclip question.

Alright everyone this is a bit of a complicated setup so if I need to clarify the question just let me know. I have a model: class IconSet < ActiveRecord::Base has_many :icon_graphics end This Model has many icongraphics: class IconGraphic < ActiveRecord::Base belongs_to :icon_set has_attached_file :icon has_attached_file :f...