ruby-on-rails

has_many "not something" :through. What conditions should I use?

I have User, Game and GameView. GameView describe what games users have seen. Trouble is I can't figure out what conditions should I use to fetch unviewed games. class User < ActiveRecord::Base has_many :game_views has_many :unviewed_games, :through => :game_views, :source => :game, ???what conditions??? end class GameView < Active...

Countdown Timer to activate a controller method

Hi all! I am building a survey page where users have a limited time to answer all their questions. The time given is stored in the model as @test.time_allowed, which is an integer representing seconds. I need to have a simple and non-user-tamperable way to get a timer to display on the view and execute a controller action when it winds ...

how to validate a date

how to validate a given date ...

Rails & prototype - insert a div and position it

For my rails site, when somebody attempts to delete an item, I wish to pop up a custom div (as opposed to a javascript alert box) asking for confirmation before doing so. At the moment, the way that I am doing this, is that clicking on the delete link will call a function (in application_helper.rb) as below: def show_delete_box(objec...

How to use Chronic to parse dates in a datetime text_field

I'm trying to get a text field that my users can enter in something that is parsable by the Chronic gem. Here is my model file: require 'chronic' class Event < ActiveRecord::Base belongs_to :user validates_presence_of :e_time before_validation :parse_date def parse_date self.e_time = Chronic.parse(self.e_time_before_type_...

Rails 2.3 action mailer Net::SMTPFatalError

Hi, I am sending out a confirmation email on save. When an email address in the 'CC' list is invalid I get the following error Net::SMTPFatalError (550 5.1.1 ... User unknown ): and the transaction is not saved even though it is called from the after_save method in the model observer. Should'nt the transaction be saved before the erro...

"bundle install" fail while install rspec

I am trying to install rspec-rails on Ubuntu but I am encountering some problems. Here are my exact steps: 1) Changed my Gemfile to: source 'http://rubygems.org' gem 'rails', '3.0.0.beta4' gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3' group :development do gem 'rspec-rails', '2.0.0.beta.17' end group :test do gem 'rspec', ...

jQuery Ajax POST response - knowing which form submitted?

Supposing I had a multi-form page such as: <form id="A" class="jaxy" ... /> <form id="B" class="jaxy" ... /> <form id="C" class="jaxy" ... /> Then I have some JQuery $('.jaxy').live('submit', function() { $(this).startLoadingSpinner; $.post(this.action, $(this).serialize(), $(this).stopLoadingSpinner, "script"); return false; }...

Designing a CMS to allow complete page design

Currently whenever a client wants a website I provide my own CMS however I have been wondering whether a 3rd party CMS may be easier. At the moment I have built it in ASP.Net & ASP.Net MVC (I'm thinking of moving to Ruby on Rails). A master page has 5 pagecontent areas, top, left, middle, right & footer. I then create usercontrols such...

Performance tuning in Rails

Hi , I have the rails application. i want to test the performance.so i decided to implement a tool... i download the rawk.rb file from the following URL http://ckhsponge.wordpress.com/2006/10/11/ruby-on-rails-log-analyzer-rawk/ . The tool is working greatly i can get the output like the following : **Top 20 Greatest Standard Deviat...

Cannot start server with "rack-recaptcha" gem

I have followed steps, described in rack-recaptcha readme. I have done all the steps, instead of "You have to require 'rack-recaptcha' in your gemfile." Server is unable to start, because of a following error: Booting Mongrel => Rails 2.3.5 application starting on http://127.0.0.1:3001 /System/Library/Frameworks/Ruby.framework/V...

RubyZip turning JPGs into "not JPGs, starts with 0x89"

Hi, I'm using RubyZip to compress a set of images (uploaded using Paperclip) and allow the user to download them in one file, and all works fine until I come to open an image. It wont display, and trying on Ubuntu I get the error message: "Error interpreting JPEG image file (Not a JPEG file: starts with 0x89..." So the user is downlo...

Sending several JSON requests creates a 500 error

This JSON post works, but if I start clicking them quickly, they start returning 500 errors. I'm guessing this is because they're not queueing correctly, and they fall apart when they can't go out one by one. Is there a way to queue this in JSON? Here's my button in HAML : = f.check_box :has_sticker, :style => 'width: 20px;', :class =>...

script/poller Error

I was trying to run poller but when i run that i get error as : SCRIPT/poller run => connect to localhost failed: getaddrinfo: Name or service not known will retry(#0) in 5 Solution? ...

GWT and Ruby on Rails

Hello. We have RoR application and we are planning to make js interface(extjs or closure) in new version. Is it possible to use GWT with RoR? ...

host both test and development for the same app in Phusion Passenger

Hi, I use passenger with nginx. I have multiple apps and they talk to each other. I configure the passenger to host these same apps in both test and dev environments. Now the problem is sometimes when I go to the dev environment on app1, and the app1 talks to the app2, but it hit the app2's test url. If I use mongrel no such proble...

Does rails have an API to check and see if times or dates exist?

Supposing a guy doesn't want users to include months or days or anything that remotely sounds like a time in his text area form. Could he use something besides regex to validate that? Is there a built-in API for that? I do use the Chronic gem somewhere else, but if I used it for this purpose, it would probably be out-of-the-box. Here's ...

Is it possible to know what exactly changed using an observer in ruby on rails?

I need send an email alert when the price of a product changes. Is it possible do this with ActiveRecord::Observer or do I need use programming logic in the edit form? ...

Remove .xml extension from ActiveResource request

Hi, I am trying to use ActiveResource to consume xml data from a third party API. I can use the RESTClient app to successfully authenticate and make requests. I coded my app and when I make a request I get a 404 error. I added: ActiveResource::Base.logger = Logger.new(STDERR) to my development.rb file and figured out the problem. Th...

How to write ruby code in css file.

Hello , I am having an rails application,in which I need a css file in such a way that its property can be changed by ruby code. ex. background_color :<%= ruby code that return background color %> So a user can set its css property and will be applicable to only that user like a theme. Thanks! ...