Hi all,
(I''m new with RoR) I''m using a migratio to import data into a
database
but nothing is being happens. I''m importing strings from a parsed
file.
this is what I have:
controller:
class UploadController < ApplicationController
def create
table = { }
params[:localized_string][:data].each_line do |line|
if line =~ /^\s* " (.*?) " \s* = \s* " (.*?) "/x
table[$1] = $2
end
end
table.each do |key, val|
LocalizedString.save(:key =>key, :value=> val)
end
end
end
model:
class LocalizedString < ActiveRecord::Base
end
view:
<h1>Importing Strings<h1>
<%= start_form_tag({:action => ''create''}, :multipart
=> true)%>
<p>
<b>Path: </b><br />
<%= file_field ("localized_string", "data"
)%>
</p>
<p><%= submit_tag "Import"%></p>
<%= end_form_tag%>
The table does get mapped on the database but no data gets imported.
I''m wondering if I''m missing something in the model...can
anybody help
me out? I''ll appreciate your help.
--
Posted via http://www.ruby-forum.com/.
Hi Robert -- On 2-Aug-06, at 11:47 AM, Robert Smith wrote:> class UploadController < ApplicationController > def create > table = { } > params[:localized_string][:data].each_line do |line| > if line =~ /^\s* " (.*?) " \s* = \s* " (.*?) "/x > table[$1] = $2 > end > end > table.each do |key, val| > LocalizedString.save(:key =>key, :value=> val) > end > end > endJust taking a quick look here, but doing LocalizedString.save won''t work without an instance of LocalizedString. Try LocalizedString.create instead, which will create a new object and save it in one go. I think that''s what you want. /Jeff -- http://re.visioni.st http://quotedprintable.com
I found the answer to my question. :) thanks anyway -- Posted via http://www.ruby-forum.com/.
Jeffrey Hardy wrote:> Hi Robert -- > > On 2-Aug-06, at 11:47 AM, Robert Smith wrote: >> end >> end >> end > > Just taking a quick look here, but doing LocalizedString.save won''t > work without an instance of LocalizedString. Try > LocalizedString.create instead, which will create a new object and > save it in one go. I think that''s what you want. > > /Jeff > > -- > http://re.visioni.st > http://quotedprintable.comthanks Jeffrey, that''s what it was. Thanks for your help. :) Robert -- Posted via http://www.ruby-forum.com/.