Hi,
Need help to understand and differences when to use form_tag and
form_for…
I have a simple app that runs on creating article and allow user to
upload picture. I have no problem to have a form using form_for to
create a form to allow user to create a new article and upload an
image.
see below…new.rhtml
New photo
Upload your picture and enter a description !
<% form_for(:photo,
@photo, :url=>{:action=>'create'}, :html=>{:multipart=>true}) do |
form| %>
Country : <%= form.text_field :country %>
City : <%= form.text_field :city %>
Title : <%= form.text_field :title %>
Description :<%= form.text_field :description %>
Upload : <%= form.file_field :image_file %>
<%= submit_tag “Create” %>
<% end %>
<%= link_to ‘Back’, :action => ‘list’ %>
But when i need user to update the form, allowing them to upload
another new picture to overwrite the previous picture, i cant…the
code is below
see below…edit.rhtml
<% form_for(:photo, :id => @photo.id, :url =>{:action
=>‘update’}, :html=>{:multipart=>true}) do |form| %>
<%= render :partial => ‘form’ %>
<%= submit_tag ‘Edit’ %>
<% end %>
=====
code for _form.rthml
<%= error_messages_for ‘photo’ %>
Country
<%= text_field 'photo', 'country' %>
City
<%= text_field 'photo', 'city' %>
Title
<%= text_field 'photo', 'title' %>
Description
<%= text_field 'photo', 'description' %>
Upload New Image
<%= file_field 'photo', 'binary_data' %>
===========
The edit.rhtml renders a html page where i am unable to capture the
article id (photo.id) for me to update the info…
It need to have an example, whereby the edit.rhtml allow multipart
=>true and at the same time capture the ActiveRecord id for update
purposes…
I have check the Agile web development book, but there is no such
example…anyone please help me ?
thks alot