ruby-on-rails

Rails - Iterate find_by results into a select dropdown

I'm new to rails and need some help with iterating through a sql result. I have a method in my model that uses find_by: def self.find_country() @countries = CountryTable.find_all_by_country_status('Y', :select => "country_name") @countries.each do |c| puts "#{c.inspect}" end end This is what I have in the view: <%= select_...

Rails 3 -- Bundler/Capistrano Errors

I have a basic Rails 3 app working locally on my development box, but want to test out deploying early on to make sure everything works. I'm using Capistrano to deploy. When I run cap deploy (after all the other necessary setup), it breaks on this command with this error: [...] * executing 'bundle:install' * executing "bundle install ...

Am I abusing of "rescue"?

I use rescue for everything, not just for "rescuing" exceptions. I mean, I just love the way it spares me verification and double checking data. By example, lets say I have a model Item what may or may not have a User. Then, when I want to get the owner's name of the item I write: item.user.name rescue "" instead of something like i...

How can I force Rails (2.3.x) MemCacheStore to read a value from the server?

Long story short: I have some controller logic that requests a value from the cache X times, expecting to get a different value on subsequent requests if it has in fact changed on the cache server in between cache requests (this is all within the context of a single HTTP request). However it seems that Rails MemCacheStore wraps itself w...

Ruby on Rails 3 Session/Cookie Usage

Rails 3.0 After doing rake db:sessions:create then adding the line of code in the session_store.rb, CouponManager::Application.config.session_store :active_record_store What else needs to be done before I'm capable of using sessions like session[:ttl_qty] = 5 ...

Associating notes with different entities in a database

At my job, we have judges perform a variety of tasks, e.g., rate movies or compare two pieces of text. We're in the process of designing a new database to hold all our data (we have some data already, but the database it's in is pretty hack), and I'm starting to build a Rails analytics application that will serve as a dashboard on these...

Rails Foreign Key Issue

Sorry if this question seems simple, I am very very new to Rails (just started learning a few days ago), but after consulting Google and "Agile Web Development with Rails" I can't find the answer. I have an issue with Rails 2.3.8 creating a foreign key on two models. My tables look like this: cars manuf...

link_to :action => 'create' going to index rather than 'create'

I am building a fairly simple recipe app to learn RoR, and I am attempting to allow a user to save a recipe by clicking a link rather than through a form, so I am connecting the user_recipe controllers 'create' function through a link_to. Unfortunately, for some reason the link_to is calling the index function rather than the create. ...

How to DRY up a ruby conditional structure needed for Rails

I'm finding I often have to use a structure to avoid a Rails error of undefined method 'name' for nil:NilClass. The structure looks like this: if country.state country.state.name end It seems like a classic case of repeating oneself with country.state appearing twice in one simple block. Is there any way to DRY this up? ...

How to implement a function called in the method "onUpdate" when using sortable.create in Rails

Hi - I am creating an application using ROR and would like to know how I can implement a function which I want to call when using "sortable.create". Below is a sample code from my "*.html.erb" file. <script type="text/javascript"> Sortable.create("table_retain", { tag:"tr" , dropOnEmpty: true, onUpdate: function() { alert ('Up...

Rails 3, how add a associated record after creating a primary record (Books, Auto Add BookCharacter)

Hello, Rails newbie... trying to understand the right way to do things... In my app users can create a Book ( I have that working) What I want to happen is when a user creates a book, a record is added to the BookCharacters Table, something like (id, book.id, user.id, characterdescription.string.) When the book is created, the user wh...

Rails Prototype and Unobtrusive Javascript

I've been programming rails for only a few months and was first introduced to RJS in 2.3.8 rails. Though things have changed slightly and am a little confused with this "unobtrusive javascript". From reading google, I'm understanding it as like removing the javascript inline to a seperate file. From what I understood of .rjs was it was...

Ruby on Rails: How would I handle 10 concurrent users? Do I need more CPU?

Sorry if this might seem obvious. I've monitored that a web request on my Rails app uses 30-33% of CPU every time. For example, if I load a web page, then 30% of CPU is used. Does that mean that my box can only handle 3 concurrent web requests, and will stall if there are more than 3 web requests (i.e. I'll get a 100% CPU)? If so, does ...

Given the following User<>Project<>Permissions<>Roles Model, how to obtain a project's team members?

Given the following: class User < AR::B has_many :permissions has_many :projects, :through => :permissions end class Project < AR::B has_many :permissions has_many :users, :through => :permissions end class Role < AR::B has_many :permissions end class Permission < AR::B belongs_to :user belongs_to :project ...

pagination and memcached in rails

What's the best way to cache a paginated result set with rails and memcached. For example posts controller def index @posts = Rails.cache.fetch('all_posts') do Post.paginate(:conditions => ['xx = ?', yy], :include => [:author], :page => params[:page], :order => 'created_at DESC') end end This obviously doesn't work when the params[:...

Rails RJS AJAX Question

Rails - 3.0 - Trying to make an ajax call but I run into an error. Controller - Home def test end View - home#index <div class="test"> Testing here </div><%= link_to 'Test', test_path, :remote=>true %> View - test.rjs page[:test].replace_html :partial => "home/blah" When I click on the link I get this - try { $("test"...

How to model a schedule in Rails?

Using Ruby on Rails 2.3.8, I'm wondering how to represent a schedule for model that handles "reminders". Examples of reminder: "Must do ABC", Remind me in 3 days "Must do DEF", Remind me in 5 weeks "Must do XYZ", Remind me on 2nd Oct 2010 at 5 pm So, the Must do... goes into a description column. But how to deal with the fact that wh...

How do I see what's going on with queued jobs using delayed_job?

I have been running delayed_job and was hitting some errors, but now I don't know what is sitting in the job queue or what's going on with them.... How can I figure that out so I can debug whether it is able to execute what has been put in the queue? Here is where I call the job (it is part of a cron task) and the mailer it calls: c...

Why does Sunspot change the `self` in the search DSL block?

I noticed (and verified in the sunspot code) the following behavior class Foo < ActiveRecord::Base def bar search_str = "foo" Boo.search do keywords(search_str) p self.id p self end end end In the code above, the DSL block can access the variables defined in the context. But the self inside block, poin...

Is there a good tutorial showing how to implement acts_as_commentable in a rails application?

The readme does not show how to handle the controller and view aspects of setting up this plugin. I have been searching for a couple hours and can't find anything that shows how to use this plugin. ...