Using migration--newbie

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:

Importing Strings

<%= start_form_tag({:action => 'create'}, :multipart => true)%>

Path:
<%= file_field ("localized_string", "data" )%>

<%= submit_tag "Import"%>

<%= 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.

I found the answer to my question.

:slight_smile:

thanks anyway

Hi Robert –

On 2-Aug-06, at 11:47 AM, Robert S. 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.com

Jeffrey H. wrote:

Hi Robert –

On 2-Aug-06, at 11:47 AM, Robert S. 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.com

thanks Jeffrey, that’s what it was. Thanks for your help. :slight_smile:
Robert