Posted by Chris Blackburn Thu, 19 Jun 2008 01:01:00 GMT

schema.rb for states table
create_table "states", :force => true do |t|
  t.string   "name"
  t.string   "abbreviation", :limit => 2
  t.datetime "created_at"
  t.datetime "updated_at"
end
cities_controller.rb
# GET /cities/new
# GET /cities/new.xml
def new
  @city = City.new
  @states = State.find(:all, :order => :abbreviation)

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @city }
  end
end
new.html.erb view for cities_controller.rb
<% form_for(@city) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :state_id %><br />
    <%= f.collection_select(:state_id, @states, "id", "abbreviation") %>
  </p>
  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>

Posted by Chris Blackburn Thu, 31 May 2007 18:10:00 GMT

If you are experiencing the error: “undefined class/module MyClass” when fetching data from memcached, be assured that you are not alone. It is a known bug and the simplest way I know of to get around it is to reference the class or classes right before you retrieve data from the cache.

For example, if the following code causes the problem:

if not (genres = Cache.get(key))
  genres = Genre.find(:all, :condition => "platform_id = 1")
  Cache.put(key, genres, 60*60*24) # cache for 1 day
end

… then this code will work around it:

Genre
if not (genres = Cache.get(key))
  genres = Genre.find(:all, :condition => "platform_id = 1")
  Cache.put(key, genres, 60*60*24) # cache for 1 day
end

Notice the ‘Genre’ reference before the if statement. Some have reported success by using the ‘model’ statement within the controller, however that is deprecated. This workaround will get you going again.

Older posts: 1 2