2013-07-24 40 views
0

我建立的红宝石矿。但下面的RoR应用程序似乎并不运行`为什么form_ tag代码在ruby mine 5.4.3.2.1中不起作用?

<%= form_tag upload_index_path({:action => 'uploadFile'}, 
           :multipart => true) do %> 
<p><label for="upload_file">Select File</label> : 
    <%= file_field 'upload', 'datafile' %></p> 
<%= submit_tag "Upload" %> 
<% end %>` 

This code is in my view file. I am trying to build a site where i can upload files. Everything appears good but when i click the upload button the file doesn't get uploaded only the url changes. Why is that?? 

这是我的控制器代码

class UploadController < ApplicationController 
    def index 
    render :file => 'app\views\upload\uploadfile.html.erb' 
    end 
    def uploadFile 
    post = DataFile.save(params[:upload]) 
    render :text => "File has been uploaded successfully" 
    end 
end 

这是我的模型代码

class DataFile < ActiveRecord::Base 
    # attr_accessible :title, :body 
    def self.save(upload) 
    name = upload['datafile'].original_filename 
    directory = "public/data" 
    # create the file path 
    path = File.join(directory, name) 
    # write the file 
    File.open(path, "wb") { |f| f.write(upload['datafile'].read) } 
    end 
end 

我一直没有找到解决办法。我一直在尝试一个星期。

+0

如何[Rü保存文件的应用程序?最好使用宝石回形针。 – Debadatt

回答

0

在你的form_tag声明,从路径选择删除多如下:

<%= form_tag upload_index_path({:action => 'uploadFile'}) , :multipart => true do %>      
    <p> 
     <label for="upload_file">Select File</label> : 
     <%= file_field 'upload', 'datafile' %> 
    </p> 

    <%= submit_tag "Upload" %> 

<% end %> 

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag

+0

没有工作...... –

+0

你可以发布任何中断时Rails服务器显示的输出。 – robinjohnobrien

相关问题