ruby-on-rails

jQuery not working with Rails

So I'm trying to get some basic jQuery code with Rails working, but it doesn't seem to be working out. I've looked around and it seems like I'm following all of the directions correctly and have tried it in multiple browsers with no avail. Essentially, I'm just trying to slide up a div on document ready, but it just stays there :( <%= j...

using a non-integer id column in ActiveRecord

Are there any gotchas to using a non-integer column for the id in an ActiveRecord model? We're going to be using replicated databases, with copies of a Rails app writing to those databases in different datacenters. I'm worried that with normal IDs we'll get collisions between newly created rows in different datacenters. Our DBA has su...

How to use rspec to test named routes?

Hi there, Given I have a named route: map.some_route '/some_routes/:id', :controller => 'some', :action => 'other' How do I use the routing spec file 'spec/routing/some_routing_spec.rb' to test for that named route? I've tried this after the "describe SomeRouteController" block and it doesn't work, I get 'undefined method "helper": ...

Named Routes & link_to problem

I have the following routes set up: map.people 'people(.:format)', :conditions => { :method => :get }, :controller=>"people", :action=>"index" map.connect 'people(.:format)', :conditions => { :method => :post }, :controller=>"people", :action=>"create" map.new_person 'people/new(.:format)', :conditions => { :method => :get }, :controlle...

How to find date of end of week in Ruby?

Hi, I have the following date object in ruby Date.new(2009, 11, 19) How would you find the next friday? Cheers ...

How can I seamlessly handle migrations in production databases during deployment in Rails?

Is it standard practice to put db:migrate in my capistrano task, maybe before updating the code? I don't want to forget to add a column to production and get errors so I feel like there should be a seamless way to do this. Is there anything wrong with doing it the way I mentioned? ...just wondering what the standard practice is here ...

NameError (uninitialized constant *nameofcontroller* error in Rails

I am new to RoR and trying simple CRUD operations without scafolding. I have a model called ccword, with controller named WordsController. Problem is I am creating simple 'create' and leading me to this error: NameError in C cwordsController#create uninitialized constant CCwordsController This is how my create method in my controller...

Rails, update 2nd select with static data from partial, based on initial select.

I have a rails form where the end user is going to drop down a list of categories, select a category. I need this selection to update the next select drop down. The issue is that the 2nd select needs to be populated by static data from a partial. The reason for this, is that its a product registration page, that includes more option...

AJAX/Javascript Error Ruby on Rails...

Ok so here is where I am at. I have three different things here and I am very close to getting it to work. I have a form with a checkbox = value of 1 that collects a "vote" for a "post" and sends it to the database with the post_id. This works great. I have a partial template that rendors that particular posts votes back underneath t...

Most elegant way of updating comments in a rails blog app

I have a fairly standard blog app with the usual post and comments controller/models along with a user model for leaving comments. So in the user model I have has_many :comments And in the the comments model belongs_to :post belongs_to :user All very straight forward. In the app I'm creating I want the comments to act a little di...

Rails ActiveRecord: Locking down attributes when record enters a particular state

Wondering if there’s a plugin or best way of setting up an ActiveRecord class so that, for example, when a record enter the "published" state, certain attributes are frozen so that they could not be tampered with. ...

ASP.NET MVC fuzzy path to the pit of success?

I'm interested in adding ASP.NET MVC to my skillset. However my reticence comes from the fact that there seems to be a lot of "fuzziness" when people talk about implementing applications and how to adhere to the rules of the MVC architecture. I've heard Microsoft quoted as wanting developers to fall into the pit of success. With that ...

Hiding Checkbox & Assigning Value - Ruby on Rails - Easy Question...

I am trying to hide a checkbox and assign a default value of 1 such that the submit button only shows. Here is my form. Just wondering as the proper format as I am new to rails. I think you can do this with helpers but was wondering if I can just include it in the form. Here is the form: <% remote_form_for [@post, Vote.new] do |f| %> ...

ROR ActiveRecord attribute handling with a callback before_update

This code produces an ActiveRecordError: Callbacks must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method." before_update :check_instock, :unless => Proc.new { |inventory| inventory.needed.nil? } def check_instock if needed < amount ...

Displaying record count - Ruby on Rails - Ajax

I am new to rails so sorry if sometimes I don't make much sense. Here is what I am trying to do. I am trying to build a vote system. So next to a blog post there is a link that says 'vote' (will probably say like later). So far I have working: when the vote button is clicked, a value of '1' is delivered to the vote table and then that pa...

Changing user roles through a form

I'm trying to create a Rails form that allows an admin user to change the assigned roles of other users. The form I've created registers changes to the user (such as password or login changes), but doesn't register changes to the user's role, which is a separate model. I'm using Acl9 for role-based authentication, which uses a User ...

Partial not receiving all variables from :locals

In my controller I have: - @items.each do |item| = render :partial => 'item', :locals => { :item => item, :draggable => true } And in the item partial I have: %span{:id => "item_#{item.id}", :class => 'item'} = item.name - if defined?(draggable) = draggable_element "item_#{item.id}", :revert => true This is not working, h...

Duplicates in hash

I am working on http://rubyquiz.com/quiz28.html and am almost done except for one little bug. In the following: prompts is an array, which for arguments sake is ["one", "two", "three", "three", "four] def ask_reader(prompts) @answers = {} for p in prompts puts "Give me a #{p}" @answers[p] = gets.chomp end en...

Authlogic-oid with ONLY OpenID

I am implementing an internal site, for which I want our company's OpenID server to be the only means of registering and logging in. To be more specific, I don't even want a normal email and password/salt to be stored for the users in this site. I am using authlogic with the authlogic-oid plugin, but I am getting these errors whenever I...

MongoMapper and migrations

I'm building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document key :some_key, String end Later in version 2, I realize that I need a new required key on the model. So, in version 2, SomeModel now loo...