hello you all, I''m new with Ruby on Rails. I''m developing an application. I got the follwoign erro, can anybody give a hand? ArgumentError in AdminController#import_strings wrong number of arguments (0 for 1) RAILS_ROOT: ./script/../config/.. Request Parameters: {"commit"=>"Import", "description"=>{"description"=>#<StringIO:0x36311f0>}, "variable"=>["English"]} Show session dump --- flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} This is my code (controller): def import_strings(a_string) table = { } IO.foreach(''#{a_string}'') { |line| if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x table[ $1 ] = $2 description = Description.new description.Index_Number = [$1] description.Name_Of_String = [$2] description.save end } This is my cod (view): <h1>Importing Strings<h1> <%= start_form_tag({:action => ''import_strings''}, :multipart => true)%> <p> <b>Lenguage:</b><br/> <%= select("variable", nil, @array_of_lenguages) %> </p> <p> <b>Path: </b><br /> <%= file_field "description", "description"%> </p> <p><%= submit_tag "Import"%></p> <%= end_form_tag%> -- Posted via http://www.ruby-forum.com/.
Your function takes one argument but your not passing it any from your view. On 7/24/06, David Furgeson <ricardo.orozco@hp.com > wrote:> > hello you all, > > I''m new with Ruby on Rails. I''m developing an application. I got the > follwoign erro, can anybody give a hand? > > ArgumentError in AdminController#import_strings > wrong number of arguments (0 for 1) > RAILS_ROOT: ./script/../config/.. > Request > Parameters: {"commit"=>"Import", > "description"=>{"description"=>#<StringIO:0x36311f0>}, > "variable"=>["English"]} > > Show session dump > > --- > flash: !map:ActionController::Flash::FlashHash {} > > > Response > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > > This is my code (controller): > > def import_strings(a_string) > table = { } > IO.foreach (''#{a_string}'') { |line| > if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x > table[ $1 ] = $2 > > description = Description.new > description.Index_Number = [$1] > description.Name_Of_String = [$2] > description.save > > end > } > > This is my cod (view): > <h1>Importing Strings<h1> > <%= start_form_tag({:action => ''import_strings''}, :multipart => true)%> > <p> > <b>Lenguage:</b><br/> > <%= select("variable", nil, @array_of_lenguages) %> > </p> > <p> > <b>Path: </b><br /> > <%= file_field "description", "description"%> > </p> > > <p><%= submit_tag "Import"%></p> > > <%= end_form_tag%> > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/c4eb21d6/attachment-0001.html
Stephen wrote:> Your function takes one argument but your not passing it any from your > view.Hi Stephen...thanks for your help. I''m trying to follow a books example (uploading a picture) and they didn''t pass any parameters in thier view. Rather they created an attribute in the model. This is what I did: My controller code: class UploadController < ApplicationController def get @description = Description.new end def save @description = Description.new(params[:description]) if @description.save redirect_to(:action=>''show'', :id =>@description.id) else render(:action=>:get) end end end My model code: 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 def description=(description_field) self.Index_Number = [$1] self.Name_Of_String = [$2] end end My view model: <h1>Importing Strings<h1> <%= start_form_tag({:action => ''save''}, :multipart => true)%> <p> <b>Lenguage:</b><br/> <%= select("variable", nil, @array_of_lenguages) %> </p> <p> <b>Path: </b><br /> <%= file_field ("description", "description")%> </p> <p><%= submit_tag "Import"%></p> <%= end_form_tag%> I''m confused because the book uploads pictures but I want to upload key-values read and parsed from an incoming file. Am I comparing two things totally different? What step should I take. thanks so much for your time -- Posted via http://www.ruby-forum.com/.