Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use one partial in different contexts
    primarykey
    data
    text
    <p>i am new to rails and try to do the following:</p> <p>I would like, because i use Bootstrap, to have a partial for a input field, with it's label and a little icon i called symbol in this case. <br /><br /> Here is my view: <br /></p> <pre><code>&lt;%= form_for(@user, :class =&gt; "form-horizontal" ) do |f| %&gt; &lt;fieldset&gt; &lt;%= render 'shared/text_field', function: f, tag: :name, symbol: '&lt;i class="icon-user"&gt;&lt;/i&gt;' %&gt; &lt;%= render 'shared/text_field', function: f, tag: :email, symbol: "@" %&gt; &lt;%= render 'shared/password_field', function: f, tag: :password, symbol: '&lt;i class="icon-log"&gt;&lt;/i&gt;' %&gt; &lt;%= render 'shared/password_field', function: f, tag: :password_confirmation, alt: "Passwort wiederholen", symbol: '&lt;i class="icon-log"&gt;&lt;/i&gt;' %&gt; &lt;!-- SUBMIT --&gt; &lt;%= f.submit "Anmeldung", :class =&gt; "btn btn-primary" %&gt; &lt;/fieldset&gt; &lt;% end %&gt; </code></pre> <p><br /> Here a subpartial for normal input fields:<br /></p> <pre><code>&lt;%= render 'shared/bootstrap/input_field' %&gt; &lt;% content_for :label do %&gt; &lt;%= function.label tag, :class =&gt; "control-label", :for =&gt; "prependedInput" %&gt; &lt;% end %&gt; &lt;%content_for :symbol do %&gt; &lt;%= raw(symbol) %&gt; &lt;% end %&gt; &lt;% content_for :field do %&gt; &lt;%= function.text_field tag, :class =&gt; "input-xlarge", :id =&gt; "prependedInput", :size =&gt; "6" %&gt; &lt;% end %&gt; </code></pre> <p>(there is also a subpartial for password fields, basicly exchanging function.text_field with function.input_field) <br /> And here is the input_field which is rendered: </p> <pre><code>&lt;div class="control-group"&gt; &lt;%= yield :label %&gt; &lt;div class="controls"&gt; &lt;div class="input-prepend"&gt; &lt;span class="add-on"&gt;&lt;%= yield :symbol %&gt; &lt;/span&gt; &lt;%= yield :field %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>So my question is: how can i solve this Problem in a nice and easy way (this things happend while refactoring and it got even worse then better) and how can i make it work, because by now something like this happens: <a href="http://pastebin.com/bNsgT9AR" rel="nofollow">http://pastebin.com/bNsgT9AR</a> so yield puts with each content_for the content and the content before into the place (except the last one)</p> <p>It would be great to hear nice solutions from you, there has to be a so much nicer way as almost always in Rails.</p> <p>Greetings form Germany ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload