I'm running Ruby 1.9.2 and Rails 3.0.7. I'm having problems inserting
data into a temporary database table.

I can create a temporary table with the code:
<code>
class TempHelper
def self.create_temp
begin
ActiveRecord::Schema.define do
create_table (:temps), :temporary => true do |t|
t.string :name
t.string :value
end
end
return true
rescue Exception => err
return err.message
end
end
end
</code>

But I can not insert any data into it:
<code>
irb(main):001:0> TempHelper.create_temp
-- create_table(:temps, {:temporary=>true})
-> 0.0440s
=> true
irb(main):002:0> Temp.count
=> 0
irb(main):003:0> t = Temp.new(:name => 'name', :value => 'value')
=> #<Temp id: nil, name: "name", value: "value">
irb(main):004:0> t.save
NoMethodError: undefined method `name' for nil:NilClass
from /usr/local/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/
activesupport-3.0.7/lib/active_support/whiny_nil.rb:48:in
`method_missing'
...
irb(main):005:0> t.class
=> Temp(Table doesn't exist)
</code>

I can provide the complete traceback if it will help.

I do not understand why this is not working. For this testing, I'm
using sqlite3. Is that the problem?

Thanx in advance.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Jsnark at Dec 12, 2011 at 1:58 pm
    It's now been a month since I made this post and have not received a
    response.

    I am assuming that is because the only way to use temporary database
    tables from Ruby is to write raw SQL.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Frederick Cheung at Dec 12, 2011 at 4:25 pm

    On Dec 12, 1:57 pm, jsnark wrote:
    It's now been a month since I made this post and have not received a
    response.

    I am assuming that is because the only way to use temporary database
    tables from Ruby is to write raw SQL.
    or because not every person reads every message.

    Nosing it around it appears that, for mysql and sqlite3 temporary
    tables don't appear in the thing rails uses to decide whether a table
    exists, so rails will refuse to believe that the table exists, which I
    imagine is the root of the problem

    Fred

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Jsnark at Dec 13, 2011 at 1:39 pm
    Fred,

    Thank you so very much for your response.

    If I am understanding you correctly, you are confirming my conclusion
    that the only way to use temporary tables with sqlite3 and mysql is to
    use raw SQL.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 12, '11 at 2:35p
activeDec 13, '11 at 1:39p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Jsnark: 3 posts Frederick Cheung: 1 post

People

Translate

site design / logo © 2021 Grokbase