Form Help In Hanamirb (Lotusrb)

131 Views Asked by At

Does hanami support below code?

<%= form_for :question, routes.question_path. method: 'post' do %>
<div class="box-body">
  <div class="row">
    <div class="box-body pad">
       <textarea id="content"></textarea>
    </div>`enter code here`
  </div>
</div>
<% end %>

And how can I can do it in my template?

2

There are 2 best solutions below

2
On

Though this is possible, the official Hanami guide discourages it as it has to resort to monkey patching in order to work with the various template engines.

You can read more about it here.

An alternative approach is to define a single form rendering method in your view, like this:

def form
  form_for :question, routes.questions_path, method: 'post' do
    div(class: 'box-body') do
      div(class: 'row') do
        div(class: 'box-body pad') do
          text_area :content, id: 'content'
        end
      end
    end
  end
end

Then, somewhere in your template, you can call it like this to render the form:

<%= form %>
0
On

And I'm supported by author the best way I want is:

<form action="<%= routes.question_path %>" method="POST">
  <input type="hidden" name="_csrf_token" value="<%= csrf_token%>">
<!-- rest of the form goes here -->
</form>

Maybe it's help for someone else.