ruby-on-rails

rails session questions?

i run my rails program in linux , then i shutdown , after i run it agian, server report session are expired, ...

On Ruby on Rails, <%= or <% should only matter whether it is show or no show, but why will it give compile error?

The following code: <div id="vote_form"> <%= form_remote_tag :url => story_votes_path(@story) do %> <%= submit_tag 'shove it' %> <% end %> </div> gives compilation error while if the first <%= is replaced with <%, then everything works. I thought they only differ by "show" or "not show", but why will it actually cause a comp...

Current date in rails form

Hi, Im learning rails and exploring a bit away from the book and creating a simple application with added functionality as i increase my knowledge. Im writing a simple blog application and i have a field in the form called date added, i don't want this to be a field i want it to get the date from the server and place it in to the datab...

Associating Models with Polymorphic

I am trying to associate Contacts with Classes but as two different types. Current_classes and Interested_classes. I know I need to enable polymorphic but I am not sure as to where it needs to be enabled. This is what I have at the moment class CreateClasses < ActiveRecord::Migration def self.up create_table :classes do |t| ...

Rails eager loading

HI, I have a Test model, which has_many questions, and Question, which has_many answers... When I make a query for a Test with :include => [:questions, {:questions => :answers}] ActiveRecord makes two more queries to fetch the questions and then to fetch the answers - it doesn`t join them!!! When I do the query with :joins ActiveRecord m...

Can Ruby on Rails's RJS give out static Javascript code to handle user interaction?

So it looks like on RoR, when Ajax (using form_remote_tag) returns a success code, Javascript is also returned to handle the visual effects. (this is the RJS mechanism) using Fiddler, I do see the following response: try { Element.update("vote_score", "Score 58"); $("vote_score").visualEffect("highlight"); } catch (e) { alert('RJS erro...

Rails: bi-directional has_many :through relationship

I have three models in a Rails application: Game represents an instance of a game being played. Player represents an instance of a participant in a game. User represents a registered person who can participate in games. Each Game can have many Players, and each User can have many Players (a single person can participate in multiple game...

HTML5 -- server side

How much does it matter what server side language is used for building a web app to take advantage of HTML 5? It seems to me that the ruby community will probably have the fastest uptake, and as a result the most support. Does that seem right? If I want to make a serious investment in HTML5, what server side language should I use? ...

MIgrations and Rspec

Hi, I'm developing a Rails application with Rspec for unit testing. Weeks ago, Rspec used to migrate the database to the last version automatically when executing 'rake spec', but now it doesn't do it automatically, I have to implement everything for myself. This happens in test environment, because my development data doesn't desap...

Rails on Subdomain and Custom Port

Hi, I have to run rails on a shared host for a client via cPanel. The application is running on a subdomain and non standard port. I am using Authlogic, so on the first visit it detects I am not logged in and I get a page with: You are being redirected. Clicking on that I get the login form, which then takes me to the target page, ...

Why is Rails before_filter called twice when the controller is subclassed?

I'm at Rails 2.3.5 and I have this problem: class BaseController < ApplicationController before_filter :foo, :only => [:index] end class ChildController < BaseController before_filter :foo, :only => [:index, :show, :other, :actions] end The problem is that on ChildController, the :foo before filter gets called twice. I've tried ...

Foreign Key Relationship in Rails

Hi...I am a beginner in Rails and I read that the Rails enforces the foreign key relationships at the model level and also at the database level in the migration file, while creating the table. Is it really necessary and what kind of advantage does it provide ...

How do you reload your environment while using script/console?

I think I have seen Ryan Bates do it one of his screencasts, but I can't find it. I believe there is a command you can run while in script/console that lets you reload your models (if say you have made a change) so that you dont have to exit and then recall the console. Any Ideas? ...

finding process bottlenecks rails/ruby

I just got started with rails, and when I testing in development mode, I see in the logs that my Mailer action is taking 1175ms. Is there anyway to find out what exactly is the slow step? Also, there is a line that says (View:2, DB:1). I assume the DB means number of database lookups, but what about the view? ...

How do I enable automatic reloading of view files in development mode in JRuby on Rails?

I am developing an app in JRuby on Rails. For some reason, when I edit the view files, the development JRuby Mongrel server doesn't reload them. The perplexing thing is that after editing the controller files, the server reloads them just fine on the next request. This would be annoying even when using MRI Ruby, however starting up JRub...

Drawing information from relational databases in Rails

I am trying to pull the name of the Artist from the Albums database. These are my two models class Album < ActiveRecord::Base belongs_to :artist validates_presence_of :title validates_length_of :title, :minimum => 5 end class Artist < ActiveRecord::Base has_many :albums end And here is the Albums Controller def index ...

Guide to migrate from delayed_job to resque?

Does anyone have or know of a guide for how to migrate from Delayed Job to Resque? I can't find any on Google and figure I must not be the first one doing this. Just a general list of changes that need to made and things to watch out for would be great. ...

AssociationTypeMismatch with Expected Type on Nested Model Forms

I'm getting this exception when doing a nested model form: ActiveRecord::AssociationTypeMismatch in RecipesController#update Ingredient(#35624480) expected, got Ingredient(#34767560) The models involved are Recipe and Ingredient. Recipe has_many and accepts_nested_attributes_for :ingredients, which belongs_to :recipe. I get this e...

Using named_scope with counts of child models

Hi, I have a simple parent object having many children. I'm trying to figure out how to use a named scope for bringing back just parents with specific numbers of children. Is this possible? class Foo < ActiveRecord::Base has_many :bars named_scope :with_no_bars, ... # count of bars == 0 named_scope :with_one_bar, ... # cou...

How to translate find_by_sql statement into named_scope?

How do I translate the following into a named_scope? def self.commentors(cutoff=0) return User.find_by_sql("select users.*, count(*) as total_comments from users, comments where (users.id = comments.user_id) and (comments.public_comment = 1) and (comments.aasm_state = 'posted') and (comments.talkboard_user_id is null) ...