Topic: how to use file_field_tag to get the file path, with Ajax

hi

i want to upload file like image but i needn't to save it into database. model :Project(name:string,url:string)

so in the  _form.html.erb respond to Create action,  i add the code

<%= form_for [@template, @entry], remote: true do |f| %>
<%= f.text_field :name %>
<%= file_field_tag :image%>
<%= f.submit %>

in the create

  def create
    @template = Template.find(params[:template_id])
    @entry = @template.entries.create(params[:entry])
    
    image = params[:image]
    if image
    @entry.url = image.original_filename
    else
    @entry.url = "not work"
    end 

    respond_to do |format|
      if @entry.save
        format.js
      else
        format.js { render action: "new" }
      end
    end
  end

there are many problem i can't understand

1.params[:image].class => String  ?? i think it should be a Object

2.

Processing by TemplatesController#index as HTML

it should be processed as JS!

if i replace the

<%= file_field_tag :image%>

with

<%= f.text_field :url%>

it will be processed as JS

who help me explain the usage of file_field_tag

best wishes

i am a rails rookie

Re: how to use file_field_tag to get the file path, with Ajax

in the form_for set :html => {:multipart => true} then the params will be Object.

but if i reassign a variable like this

def create
    @entry = Entry.create(params[:entry])
    @entry.url = "www.railsforum.com"

    respond_to do |format|
      if @entry.save
        format.js
      else
        format.js { render action: "new" }
      end
    end
  end

it will be “Processing by EntriesController#create as HTML”
and error:"Completed 406 Not Acceptable in 117ms (ActiveRecord: 104.8ms)"

that's because the reassign will be a UPDATE in database,
how to modify the code to “Processing by EntriesController#create as JS

i am a rails rookie

Re: how to use file_field_tag to get the file path, with Ajax

the gem of remotipart will be help

i am a rails rookie