Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I create a Rails form based on an object using HAML?
    text
    copied!<p>If I have a model named Client and controller that looks like this</p> <pre><code>class ClientController &lt; ApplicationController def new @client = Client.new @client.name = "New Guy" end end </code></pre> <p>and I am using HAML, what will my view need to look like to render a form based on this.</p> <p>I have this</p> <pre><code>%p= @client.name -form_for :client, @client do |c| c.label :c.name c.text_field :c.name </code></pre> <p>but my html ends up looking like this</p> <pre><code>&lt;p&gt;New Guy&lt;/p&gt; &lt;form accept-charset="UTF-8" action="/client/new" method="post"&gt;&lt;div style="margin:0;padding:0;display:inline"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;&lt;input name="authenticity_token" type="hidden" value="orGtE1V05QIaye5kSsAi5SBdEAV0AJX9uZYUzHw5P64=" /&gt;&lt;/div&gt; c.label :c.name c.text_field :c.name &lt;/form&gt; </code></pre> <p><strong>Update:</strong> Thanks for the answers. when I change the view to </p> <pre><code>%p= @client.name -form_for :client, @client do |c| = c.label :c.name = c.text_field :c.name </code></pre> <p>I get the following error</p> <pre><code>undefined method `name' for :c:Symbol Extracted source (around line #3): 1: %p= @client.name 2: -form_for :client, @client do |c| 3: = c.label :c.name 4: = c.text_field :c.name </code></pre> <p>If I comment out lines 2,3, and 4 The name prints out fine. What am I missing?</p> <p><strong>Update 2:</strong></p> <p>If I change the view to </p> <pre><code>%p= @client.name -form_for :client, @client do |c| c.label :name c.text_field :name </code></pre> <p>no more error. Thanks.</p>
 

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