ruby-on-rails

how do i check for the existence of a method in a rails application controller?

Hi All, In my application controller, I have a method that is supposed to check for the existence of another method in a subclassed controller to set the filename of a downloaded file, but i'm having trouble making it work properly i've tried def filename begin send "filename_method" rescue NoMethodError default_filename ...

Problem caching Model instances on a constant in Rails

I am using Single-Table Inheritance (STI) on one of my models for a Rails App and I am having problems storing model objects on a constant. I have isolated the problem into a sample project and submitted it to GitHub: http://github.com/fcoury/rails-sti-caching What I am trying to do is loading a model instance (in this case a Music mode...

How do I echo a GET variable inside Rails?

I've created an iFrame component for people to integrate into their websites. The iFrame needs to be passed a GET variable from the URL string when the page is loaded on the remote site. In this case, the parent page would be called as http://www.theirsite.com/tracking=12345 and the tracking variable should be written into the html cod...

ActiveScaffold for PHP

Ruby on Rails has a bunch of plugins which extend the normal scaffolding: Lipsiadmin Hobo Streamlined ActiveScaffold Does the PHP community have anything similar? phpmyadmin is great, but it doesn't have any way to control the presentation of the data. You always get all of the data in its presentation format. These Rails framewor...

Preventing a Ruby on Rails notification daemon from emailing the same information more than once.

Part of a real estate application I'm writing will allow a user to subscribe to a location and if a new property becomes available in that location then the user will receive an email notifying them of this. I plan on runnning a background process once every few hours to handle the matching. Right now I have a model called location an...

how do i pass multiple arguments to a ruby method as an array?

Hi All, I have a method in a rails helper file like this def table_for(collection, *args) options = args.extract_options! ... end and i want to be able to call this method like this args = [:name, :description, :start_date, :end_date] table_for(@things, args) so that I can dynamically pass in the arguments based on a form commit...

Problem Upgrading Rails

I'm running Tiger and (stupidly) decided to upgrade Rails from 1.1.6 to 1.2.6. I ran the command "sudo gem install rails --include-dependencies" and everything seemed to go OK. However, after the install, when I ran the command "rails -v", I got the errors shown below. Could it be that 1.2.6 is not compatible with Tiger? I've been se...

Rails: Why does find(id) raise an exception in rails?

If there is no user with an id of 1 in the database, trying User.find(1) will raise an exception. Why is this? ...

How to make model IDs in Rails unpredictable and random

I'm writing a rails app that, by its nature, CANNOT require users to register, and thus cannot use authentication as the usual means to protect records. (I know, I know...) User information here is limited to email addresses. So I do need a way to make my model IDs unpredictable so that other IDs cannot be easily guessed. (I know, I kn...

Finding schedule overlaps with Ruby & Runt?

I'm using Ruby on Rails to build a simple application to keep track of a shop's opening and closing times and its appointments, and I'm having some trouble validating the appointments against closings in the shop's schedule. I've been using Runt to compose the schedule. For example, if the shop is open Monday morning from 9am-12pm clos...

Rails - etags vs. page caching (file cache)

What would be some advantages of using etags/stale?/fresh_when? instead of page caching (on a file cache)? Apache automatically handles etags for static files, but even if it didn't, page caching would still be better since the Rails app doesn't even get called. So, in what instances would I use the methods provided by Rails (stale?/fr...

ActiveSearch::EmptyTermError

Im using the Active_Search plugin to try and add some simple search features to my app, it works OK when their it is found somethind in the DB but if i simply run a search with no input then it gives me the error message "ActiveSearch::EmptyTermError". How do i make the search action return the correct values (which it can do), but also...

How to track views on an item a la YouTube?

I would like to be able to track views of an item in a way that I can see what items were the most viewed yesterday, last week or any given period. How can I do that using either PHP or Rails? Is there a plugin for this in Rails, or is there a simple way of doing this using PHP/memcached? ...

Beware of the pitfalls of code like: User.find(:all).each ?

I just read this as a requirement on a job listing: Aware of the pitfalls of code like: User.find(:all).each and knew instantly I was unqualified for this job because for the life of me, I don't understand what the problem is . . . Is it design related? Store the database request in a variable and THEN iterate over it? Is it dang...

What is the best plugin to handle multiple file uploads in Rails?

Lets say I have a model called Recipe. Each Recipe has several photos, a PDF file and a video. Is there a plugin out there that lets me have something as simple as Recipe.photos, Recipe.photos.first.filename, Recipe.pdf.filename, Recipe.video.filesize and so on? ...

Rails: How can I log on which site my javascript is embedded?

My site provides a javascript that shows the rate of the Dutch equivalent of the Dow Jones index. Users can embed this script in their website. It looks like this: <script type="text/javascript" src="http://www.aexscript.nl/r/gratis"&gt;&lt;/script&gt; The corresponding controller action looks like this: def show @script = Script....

Good CSS for flashes (aka info messages in Rails, growls in OSX)

I'm having difficulty getting CSS to work like I want it to for flashes (those little messages that show when you log in or do something or whatnot to confirm your action, eg in Rails). I want it to: live within any arbitrary div look like a centered box with text in it be only as big as needed to fit the text (if less than specified ...

Paperclip Plugin Is Not Functioning.

I am trying to use the paperclip plugin to let users choose an avatar pic, upload and then store it. I cant seem to get this working. I have generated the three fields: add_column :users, :avatar_file_name, :string add_column :users, :avatar_content_type, :string add_column :users, :avatar_file_size, :integer add_column ...

REST Client for Ruby Gives ActionController::InvalidAuthenticityToken

I have a RESTful Rails application with a resource called "Foo". I'm trying to use REST Client to do a put: resource = RestClient::Resource.new 'http://localhost:3000/foos/1', :user => 'me', :password => 'secret' resource.put :name => 'somethingwitty', :content_type => 'application/xml' But my app raises: ActionController::InvalidAut...

How to display next row in a set in Rails find

Hello, I want to display "tips" on my page that changes every say 30 seconds. The results from the "find" method in rails is not ordered by ID. It will be ordered by another column. What is the best way fetch "next" value. Is there a way to get number of row in result set and then find by next row id? Thanks, Tam ...