Newbie--how do i load a parsed file?

Hello there,

I’m new with ruby on rails and i don’t know how to load up a parsed file
into my database. I have my ruby script that parses it but don’t know
where to put my code, or how to combine it with view/model/controller.
this is what i have:

class Description < ActiveRecord::Base

def import_strings(a_file)
table = { }
IO.foreach(’#{a_file}’) { |line|
if line =~ /^ \s* " (.?) " \s = \s* " (.*?) "/x
table[ $1 ] = $2
end
}

description = Description.new
description.Lenguage = [$1]
description.Platform = [$2]
description.save

end

end

My view:

Importing Strings

<%=error_messages_for(“description”)%>
<%= start_form_tag({:action => ‘save’}, :multipart => true)%>


Lenguage:

<%= select(“variable”, nil, @array_of_lenguages) %>



Path:

<%= file_field (“description”, “description”
)%>


<%= submit_tag “Import”%>

<%= end_form_tag%>

I only get the actual displays but the file is never loaded into the
database. Does anybody know why?

Any help is apreciated

For starters, your form tag points at an action called ‘save’, and all
your
code is in an action called ‘import_strings’. Unless you left some other
code out, your method won’t be called by this form.

Also I don’t think you’re quite understanding what will come in from
your
form field parameter. Might want to have a look at:

http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles

HTH,
Jeff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs