开发者

NOOB question problem nesting content_tag rails

开发者 https://www.devze.com 2023-03-24 22:15 出处:网络
I have the following in my view <%= content_tag :p, :class => \"title-choose\" do %> Select image or

I have the following in my view

<%= content_tag :p, :class => "title-choose" do %>
         Select image or 
            <%=content_tag :div, :class =>"inputReplacement" do %>
                <%= form_for @upload, :remote => true, :html => { :multipart => true, :method => :post, :id => 'uploadForm', :class => "hiddenInput", :size => 13 } do |f| %>
                    <%= f.file_field :photo %>
                <% end %>
                add image from your computer:
            <% end开发者_运维百科 %>
        <% end%>

Which produces the following html:

<p class="title-choose"> Select image or </p>
<div class="inputReplacement">
<form id="uploadForm" class="hiddenInput" size="13" method="post" enctype="multipart/form-data" data-remote="true" action="/uploads" accept-charset="UTF-8">
<div style="margin:0;padding:0;display:inline">
<input id="upload_photo" type="file" name="upload[photo]">
</form>
add image from your computer:
</div>
<p></p>

Which is not what i want. I want the div wrapped in the p.

Anyone know how to do this with content_tag?

Thanks

Mitch


When I paste your view code into my Rails 3.0.7 application view (index.html.erb -- the naming is important) I have this nested properly:

<p class="title-choose">
         Select image or 
            <div class="inputReplacement">
                <form accept-charset="UTF-8" action="/globalize/translations" class="hiddenInput" data-remote="true" enctype="multipart/form-data" id="uploadForm" method="post" size="13"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="f9/6FmfCO7ezrhaUMOp+d7xOti+6UcvgzQq7M5u9HFU=" /></div>
                    <input id="globalize_translation_photo" name="globalize_translation[photo]" type="file" />
</form>                add image from your computer:
</div></p>

Just don't mind that my @upload object is different.

And yes, you really should nest <p> tags inside <div>s, not the other way around.

0

精彩评论

暂无评论...
验证码 换一张
取 消