ruby-on-rails

secure handshake between two of my websites to pass simple information?

I'm building a rails application on one domain (we'll call it domain1.com) which needs information that is only available on domain2.com (it's embedded in a certificate that only that domain can check). Basically, it's just a username, so nothing too complicated. I want to enable authentication to domain 1 by clicking a button, which w...

Complex filtering based on a many-to-many relationship

In my application, Annotations are considered "accepted" if either: They have been explicitly marked "accepted" (i.e., their state == 'accepted') They were last updated by a user who has the "editor" role My question is how to find all accepted explanations with a single DB query. Basically I'm looking for the database-driven version...

More Advanced Control Over Delayed Job workers retry

So I'm using Delayed::Job workers (on Heroku) as an after_create callback after a user creates a certain model. A common use case, though, it turns out, is for users to create something, then immediately delete it (likely because they made a mistake or something). When this occurs the workers are fired up, but by the time they query ...

rails :dependent=>:destroy being ignored.

My association option does not appear to be honored. class ClassRoom < ActiveRecord::Base has_many :class_assignments, :dependent => :destroy has_many :people, :through=>:class_assignments class Person < ActiveRecord::Base has_many :class_assignments, :dependent => :destroy has_many :class_rooms, :through=>:class_assignments c...

Create a mutually exclusive column

I have a Product model, and I want to be able to define a single Product as a "featured" product. How would I go about setting this up? I have a boolean column, "featured", but I haven't a clue how to ensure that only one of them is true at any time. ...

cattr_accessor in Rails?

Im reading the Rails guides for Rails 3 and they use this method: cattr_accessor :attribute What is this method? Is it a Rails method? I've never seen it before. ...

Rails rake: test are slow

I've been developing RoR apps for about a month in my Windows Laptop, however everytime that I run the tests it takes forever to finish (10+ minutes). On a MacBook Pro with similar hardware it runs in a fraction of the time (2 minutes). Can you guys give me any tips for speeding the whole thing up? or should I consider switching my RoR ...

%w{ models }.each do |dir| in Rails means?

In Rails guide this came up: %w{ models }.each do |dir| Could someone explain for me what %w{ models } means? Never seen it before. Is it ruby or rails specific. Thanks ...

If sorting records by a number in the record, but some records have the same number, the order is not gauranteed but shouldn't be random?

Let's say if we are sorting some records by a number in record: Name Number_of_Language_Known John 3 Mary 2 Peter 3 Mike 1 ... If we are not also sorting by Name, then the order of John and Peter is not guaranteed, but it shouldn't be random if the records never changed? I think it should be true in most environment (that is, not...

How do I freeze gems into Rails application in Rails 3?

I want to freeze a specific gem into my Rails application. In rails 2 there was this command: rake gems:unpack I can't find that command in Rails 3. ...

Parse issues when trying to use "Examples" section in Cucumber feature

No luck in googling on this error message features/manage_hand_evaluator.feature: Parse error at features/manage_hand_evaluator.feature:21. Found examples when expecting one of: comment, py_string, row, scenario, scenario_outline, step, tag. (Current state: step). (Gherkin::Parser::ParseError) Here's the setup I have for Examples secti...

Ruby on Rails -- not grokking

I've been learning a lot about web technologies recently and I want to put together a neat little website to play with html, css, javascript, flash, and what have you. I know that as far as the web browser is concerned all I need to do is send a text file (usually HTML) from my server using HTTP over TCP. I've gone through a couple o...

multiple HABTM relationships in rails

class Book < ActiveRecord::Base has_and_belongs_to_many :categories has_and_belongs_to_many :users end class Category < ActiveRecord::Base has_and_belongs_to_many :books end class User < ActiveRecord::Base has_and_belongs_to_many :books end Above is how I declared the relationships between my models. In my book controller a...

RoR+ in rjs add value from prompt to table

hi in js.rjs file i am shwoing prompt with textbox like page << "var name = prompt('Enter name:'); " i want to add the value name to the table names is it possible to do from rjs if so please guide me how to do it.. ...

Load path in Rails?

In the Rails guides they have this code to load a path. $LOAD_PATH << path ActiveSupport::Dependencies.load_paths << path ActiveSupport::Dependencies.load_once_paths.delete(path) The first one I understand. That is for ruby to know where to require files. But what does the second and the third one means? ...

Including SMSFu gives an error. How do I fix it?

How do I go about using SMSFu? I have a Posts controller and I have cloned the sms-fu files into my plugin folder. But when I include SMSFu and refresh my application, I get this error uninitialized constant PostsController::SMSFu. Where am I going wrong? Thanks. ...

If I have a function that I use both in the controller and in the views, where should I put it?

I try to be very good about keeping my view code and my controller code separate, but occasionally I run into situations where I need to use the same function in the controller and in the views. Where should I put this function so that I can access it from both the controller and the view? ...

how to change the object_id while adding row dynamically using jquery

how to change the object_id while adding row dynamically using jquery eg: <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $("#addPerson").click(function(){ $("#user tr:last ").after("<%= escape_javascript(render :partial => 'user_new', :locals =>{:user_new => User.new}) %>"); re...

How do I visit a url in rails

Im working on a small project which I need to send a couple of parameters to another server which has a web service for sending of SMS messages. I'm constructing the URL by calling a method on my controller like so, ... send_sms(number,message) sms_url = "http://sms-machine.xx.xx/sendsms/" + number + "/" + message #go to the url a...

Passing params from swfupload/uploadify to Rails app - broken?

I have an uploadify component, which sends the files back to rails application. The problem I noticed at some point is, that for some special values data passed along are altered by the flash object. On the client side I have $(document).ready(function() { $('#photo_image').uploadify({ ... 'scriptData': { authentici...