ruby-on-rails

Rails variables surviving server requests

I have an underlying ruby game-engine code and I want to use the web interface to let know the user what's going on and interact with the underlying dynamically created data. To this effect I want to create a new game variable when a link is press and I want that variable to survive till the user goes out of the page just as a flash o...

Rails SequencedHash source file.

I am testing AlumniOnRails (http://rubyforge.org/frs/?group_id=2959&release_id=17170) which is based on Rails 1.2.6 (I know it's outdated) and managed to get it up, installed the required gems, created and migrated the data and most of the basic alumni functionalities are up but one, the part that is broken seems to be missing a libr...

When to use @ in a Rails View and when to use a symbol?

<% form_tag(:action=>'update', :id=>@album.id) do %> Title: <%= text_field(:album, :title) %><br> Artist: <%= text_field(:album, :artist) %><br> Genre: <%= text_field(:album, :genre) %><br> Release Date: <%= datetime_select(:album, :release_date, :start_year=>1960) %><br> <%= submit_tag("Update") %> <% end %> In the...

Why doesn't my upload from Flash to Rails & attachment_fu work (it has something to do with the content type)?

I am trying to upload a file from a flash widget to my rails application, which uses attachment_fu to handle uplaoded images. I am using flash to upload since it makes it easy to select and upload multiple files. However, I am getting this error when the rails controller tries to call save! on the newly created ActiveRecord object: Ac...

Ruby on Rails: link updates DB

Simple RoR question...I am learning ROR and am making a simple voting app. The candidates are listed in a table and have upvote/downvote links next to their name. I am trying to make it so all the user does is click the link, the vote count is updated, and they are redirected to the initial page. I am not using scaffolding. For some re...

Is scaffold no longer valid in the Controller definition?

class AdminController < ApplicationController scaffold :album end In a Rails 1.1.6 tutorial I was instructed to put the code "scaffold :album" inside my admin controller. This is a music application containing a model called "Album". This generated an error saying that scaffold is not a valid method. Is this a deprecated/obsole...

Sending messages between users

I am building an application and it needs to have a feature whereby one user can send another user a message. The system can be the most basic type available in rails and that would suit me fine. Any ideas on how to go about this? Thanks. ...

GETing different Active Resource models in a single request

Hi! Is it possible to receive objects of different Active Resource models in a single request? For example the request "GET /user/joe/articles/1.xml HTTP/1.1" returns an object from User ("joe") and another object from Article (id "1") from the server. I know it is possible to send these objects inside an array to the client, but ARes ...

Is the Rails update_attributes method the best choice for doing an update of a model in the database?

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails 1.1.6 tutorial that I'm covering recommends using the update_attributes method for updating a model, as in the example code from my controller listed above. L...

What is the Rails way (convention wise)

Developing in rails is sometimes described as following "the rails way". And convention over configuration is also a very important aspect in rails. But what are these specific conventions? Using active record for example? ...

Ruby on Rails regex

I have these statements in a model: before_save :add_http protected def add_http if (/^http\:\/\/.+$/.match(url)) == nil str = "http://" + url url = str end end I have checked the regex in the console and it appears to be right, but when the 'url' gets saved to the db the "http://" has not been added. Any ideas? ...

Rails using named routes within helper (but with class methods)

Trying to use this method (gist of which is use self.method_name in the FunnyHelper, then call it as FunnyHelper.method_name in the view). However this causes at least a couple of problems - view methods like h() and named routes get broken (they're ok with the module method def method_name but not within any class method def self.metho...

Rails i18n Config File Management Best Practices

I'm in the process doing an i18n conversion of a RoR website. I'm using Sven Fuchs textmate bundle along with NewDesk's translate plugin. I've started with the yaml files provided by Sven Fuchs here (http://github.com/svenfuchs/rails-i18n/tree/3e1994d137e1785689e39f6e957087d3baed0011/rails/locale) I'm rapidly seeing keys getting out of ...

Rails, ActiveResource, and Pagination

What's the best way to implement pagination in a REST API so that an ActiveResource client can easily navigate paginated results? There have been some proposals, for example here and here, but being new to ActiveResource I'm wondering if there's a better way. ...

Is there a good cached memoization plugin for rails?

I have a model along the lines of: class Account < ActiveRecord::Base has_many :payments has_many :purchases def balance payments.sum(:dollar_amount) - purchases.map{|p| p.dollar_amount}.sum end end I want to memoize the balance method and store it in memcached. The problem, of course, is that the cached value needs to...

Using || in Case switch in Rails

I have a partial that I want to display in a layout only when certain pages use that layout. I've set @page_title for all my pages and thought I could use something like this: <% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%> But, the incl...

Rails doesn't like this anymore? "script/generate scaffold Album" for Album model

script/generate scaffold Album used to generate the scaffolding for a model called Album (pre-Rails 2). Is it correct that these days (post-Rails 2), you need to specify all of the required fields: script/generate scaffold Album artist:String title:String I've been following along with a tutorial on Rails 1.1.6 and have been puzzle...

Should I write my own CMS?

I am planning to begin working on my first personal project this June: a community about students. What I want to have is a wiki, full with information about universities, a forum where people can discuss and a blog with news, articles, etc, all three of them integrated to eachother. Now, the way to go seems like wordpress+mediawiki+som...

Comparing Rails vs. PHP to a non-technical audience

I recently had an interview at a small company that wants to greatly increase its web presence, including re-writing their Flash homepage and opening an e-commerce site. If given the position, I would be the sole developer on staff. I've been working with Rails for a number of years, and haven't looked at PHP in quite some time. However...

Is rake db:migrate the correct command to re-sync schema.rb with your database schema?

I ran "rake db:migrate" to re-sync schema.db with my database schema. But it failed, saying that one of my tables already exists. I think it was trying to re-create the table. If you just want to get schema.rb updated to reflected any changes you made in the database independently of Rails, what command should you use if not "rake db:mig...