Pass for to simple_form format

166 views
Skip to first unread message

maserranocaceres

unread,
May 25, 2012, 1:17:12 PM5/25/12
to SimpleForm
I want pass this form to simple_form format:

<%= form_tag @upload_info[:url], :multipart => true do %>
<%= hidden_field_tag :token, @upload_info[:token] %>
<%= label_tag :yt_video_id %>
<%= file_field_tag :yt_video_id %>
<%= submit_tag "Upload video" %>
<% end %>

Thank you very much!

Carlos Antonio da Silva

unread,
May 25, 2012, 1:19:22 PM5/25/12
to plataformate...@googlegroups.com
form_tag is not translatable to simple_form_for. SimpleForm is supposed to work the same way as form_for, which means it needs an object or :symbol to act as "object".

-- 
At.
Carlos Antonio

maserranocaceres

unread,
May 25, 2012, 1:29:28 PM5/25/12
to SimpleForm
Thank you Carlos, I have try this:


<%= simple_form_for(@upload_info[:url], :html => {:multipart =>
true }) do |f| %>
<%= f.input :token, :as => :hidden, :input_html => { :value =>
"#{@upload_info[:token]}" } %>
<%= f.input :yt_video_id, :as => :file, :input_html => {:class
=> 'upload_new_microfunc'} %>
<div class="actions">
<%= f.button :submit, "Upload video", :class => 'btn-large
btn-primary', "data-disable-with" => "#{t('.upload_video')}" %>
</div>
<% end %>

But this it does not works for me.

How can I fix this problem?

Thank you

On May 25, 10:19 am, Carlos Antonio da Silva

Carlos Antonio da Silva

unread,
May 25, 2012, 2:03:44 PM5/25/12
to plataformate...@googlegroups.com
Sorry, I'm telling you it won't work, you won't be able to achieve the exact same results.

With form_tag, you'd end up with params like this in your controller:  { :token => "abc", :yi_video_id => "123" } 
With form_for / simple_form_for, you *need* an object, so lets say you call it :upload, you'd end up with: { :upload => { :token => "abc", :yi_video_id => "123" }  }

Both have different meanings.

In any case, with SimpleForm the first line should look something like:

    simple_form_for :upload, :url => @upload_info[:url]….

Please take a look at some more examples in the readme.

-- 
At.
Carlos Antonio

maserranocaceres

unread,
May 28, 2012, 11:58:00 AM5/28/12
to SimpleForm
Thank you very much Carlos :D

On May 25, 11:03 am, Carlos Antonio da Silva
Reply all
Reply to author
Forward
0 new messages