ruby-on-rails

How do you use an attr_accessor in a select form?

I am trying to capture the identity of a gallery so that I can create a form based around that particular gallery. So I put together a select form, and threw an attr_accessor in my controller. But its failing from all sorts of directions, and I figure its a problem with my syntax. Any whiz's know this? model attr_accessor :existing_g...

Rails + SQL Server: what to put in database.yml?

I'm trying to connect Rails to SQL Server. I installed the activerecord-sqlserver-adapter and ruby-odbc gems, but I'm not sure what to put in my database.yml file. What exactly is a DSN, and why do I need it? (Is this some windows-specific thing?) What do I do if I want to use Windows Authentication, instead of specifying a username an...

Refresh Same page

I'm working on a project using ruby on rails. I want to refresh the same page when the action is called or redirect to the page where the action is called. How do i do this ? ...

ruby on rails :open flash stacked area

does anyone know if open flash plugin for rails supports stacked area chart could anyone point me to a working example of stacked area/area chart thx ...

Ruby gem Stream API like twitter

Is there any gem for ruby (i want to use it in a rails app) that does somethink like Twitter Stream API. Keep the http conection opened and send information in real time based in a query or events. ...

ActiveRecord changed? flag doesn't report changes in associated children

I've got the following situation with ActiveRecord (in Rails 2.3.8): class Order < ActiveRecord::Base has_many :documents accepts_nested_attributes_for :documents end class Document <ActiveRecord::Base belongs_to :order end Now, in a controller I want to direct the user differently depending on whether or not they made changes ...

daemon spawn : gem_original_require : no such file to load --daemon-spawn (Load Error)

I am trying to run daemon process using daemon-spawn gem. Here is the code for delayed_delta daemon process #file - script/dj #!/usr/bin/env ruby # -*- ruby -*- require 'rubygems' require 'daemon-spawn' RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) class DelayedJobWorker ENV['MIN_PRIORITY'], :max_prior...

Raise event in C# from external application?

Is there a way to raise an event in C# from an external application? In particular from Ruby? I have need to cause something to happen in C# from a rails application. ...

Ajax call made by jQuery .load function...

The problem is in the difference how browsers implement simple calls. The problem occurs while using colorbox extenstion (facebox variant). Content is loaded into colorbox with jquery load() function. When the call is made by Chrome, Accept header is set to: Accept: text/html, */*, text/javascript In case of FireFox, header looks lik...

Capistrano occasionally fails to pull git repo

Capistrano sometimes fails to pull the newest source from github, but shows no errors. On several occasions now, cap deploy did not pull the latest code from my git repo, but showed no errors in the process. Repeatingly running cap deploy does not fix the issue, but running git pull origin master on the actual server does pull in the n...

Rails 3 automatically adding X-UA-Compatible header?

Hi, Does Rails 3 automatically add a header if you are using IE8? I am seeing the meta tag for X-UA-Compatible set to "IE=8.0000" and it's messing up one of my views. I can't seem to find anything else that would be doing it, so figured I'd ask the brains here. Thanks, Ruprict ...

How to override a rails 3 template within a gem

I have a Rails 3 project where I override some scaffold templates. This is done by placing a new template in lib/templates/erb/scaffold and adding lib to my autoload path in config/application.rb (see Rasilscasts #216). Now, I'd like to package my work in a gem. (I'm new to gems...) I cannot figure out how to accomplish this in a gem....

Help optimizing ActiveRecord query (voting system)

I have a voting system with two models: Item(id, name) and Vote(id, item_id, user_id). Here's the code I have so far: class Item < ActiveRecord::Base has_many :votes def self.most_popular items = Item.all #where can I optimize here? items.sort {|x,y| x.votes.length <=> y.votes.length}.first #so I don't need to do anything ...

Possible to eager load associations with nested_attributes?

Just briefly, I have run into a dreaded 2(n) queries problem. If n = the number of skills in the database, then my characters#edit form will take 2(n) queries to load the page. It will SELECT a PlayerSkill (the join table) once every skill, and it will look up the Skill once per skill. Here is some code which I believe is pertinent to t...

RoR Devise: Using an unchangeable username

Hi there, I'm using Devise in a Rails 3 app, and I successfully configured it so that it uses a username as its authentication method instead of an email. The problem is that in the default registrations controller for devise, it calls an "update_with_password" method on the params passed in, which effectively allows users to change the...

Print running spec name

Hi, I have an issue while running my specs for a rails application with rake, it freezes on a certain spec. I would like to see what spec is running. ...

Where are Default Validation Error Messages in Rails 3.0?

Where are the default validation error messages in Rails 3.0? What is the equivalent of ActiveRecord::Error.default_error_messages[:taken], for example? I have gotten as far as finding that ActiveModel handles the errors rather than ActiveRecord, but I can't find the errors themselves. ...

getting my rails console to recognize the Session methods

I'm using the console to debug my rails app. I'm using 'Session' now instead of 'Cookies' (it worked fine with Cookies), but it's now giving me an error complaining it can't find the 'session' method. How do I get my console instance to recognize the Session methods? >> app.sign_in user NoMethodError: undefined method `session' for nil:...

Rails - Best-Practice: How to create dependent has_one relations

Could you tell me whats the best practice to create has_one relations? f.e. if i have a user model, and it must have a profile... How could i accomplish that? One solution would be: # user.rb class User << ActiveRecord::Base after_create :set_default_association def set_default_association self.create_profile end end Bu...

force user to register

Is it possible to require a "logged in" user to complete registration before he can continue on? This scenario happens when a user logges in via facebook or some other oauth/open id provider and the session does not provide all the requires registation data. Here is my application controller and I am tryint this require_registration me...