开发者

Rails form submission

开发者 https://www.devze.com 2022-12-28 10:50 出处:网络
I have a simple form to enter details of a new case (kase), it\'s working well and clicking submit stores the information and takes the user to the show.html.erb page. However, I wanted to move part o

I have a simple form to enter details of a new case (kase), it's working well and clicking submit stores the information and takes the user to the show.html.erb page. However, I wanted to move part of the form to the sidebar - to make things a little easier to see and use for the user, however, when I moved the section to the sidebar - anything entered during either a creation or edit within those sidebar fields is ignored. Any idea how I keep the fields in the sidebar, but include them as before?

<% content_for :header do -%>
    Cases
<% end -%>

<% form_for(@kase) do |f| %>
  <%= f.error_messages %>

<!-- #START SIDEBAR -->
<% content_for :sidebar do -%>
<% if @kase.avatar.exists? then %>
<%= image_tag @kase.ava开发者_运维问答tar.url %>
<% else %>
<p style="font-size:smaller"> You can upload an icon for this case that will display here. Usually this would be for the year number icon for easy recognition.</p>
<% end %>

    <div class="js_option">
    <h2>Financial Options</h2><p class="finance_showhide"><%= link_to_function "Show","Element.show('finance_showhide');" %> / <%= link_to_function "Hide","Element.hide('finance_showhide');" %></p>
    </div>

<div id="finance_showhide" style="display:none">

<ul id="kases_new_finance">

  <li>Invoice Number<span><%= f.text_field :invoicenumber %></span></li>
  <li>Net Amount<span><%= f.text_field :netamount %></span></li>
  <li>VAT<span><%= f.text_field :vat %></span></li>
  <li>Gross Amount<span><%= f.text_field :grossamount %></span></li>
  <li>Date Closed<span><%= f.text_field :dateclosed %></span></li>
  <li>Date Paid<span><%= f.text_field :datepaid %></span></li>

</ul>

</div>
<% end -%>

<!-- #END SIDEBAR -->

<% form_for (@kase), :html => { :multipart => true } do |f|  %>

  <ul id="kases_new">

  <li>Job Ref.<span><%= f.text_field :jobno %></span></li>

  <li>Case Subject<span><%= f.text_field :casesubject %></span></li>

  <li>Transport<span><%= f.text_field :transport %></span></li>

  <li>Goods<span><%= f.text_field :goods %></span></li>

  <li>Date Instructed<span><%= f.date_select :dateinstructed %></span></li>

  <li>Case Status<span><%= f.select "kase_status", ['Active', 'On Hold', 'Archived', 'Invoice Sent'] %></span></li>

  <li>Client Reference<span><%= f.text_field :clientref %></span></li>

  <li>Client Company Name<span><%= f.text_field :clientcompanyname %></span></li>

  <li>Client Company Address<span><%= f.text_field :clientcompanyaddress %></span></li>

  <li>Client Company Fax<span><%= f.text_field :clientcompanyfax %></span></li>

  <li>Case Handler Name<span><%= f.text_field :casehandlername %></span></li>

  <li>Case Handler Tel<span><%= f.text_field :casehandlertel %></span></li>

  <li>Case Handler Email<span><%= f.text_field :casehandleremail %></span></li>

  <li>Claimant Name<span><%= f.text_field :claimantname %></span></li>

  <li>Claimant Address<span><%= f.text_field :claimantaddress %></span></li>

  <li>Claimant Contact<span><%= f.text_field :claimantcontact %></span></li>

  <li>Claimant Tel<span><%= f.text_field :claimanttel %></span></li>

  <li>Claimant Mob<span><%= f.text_field :claimantmob %></span></li>

  <li>Claimant Email<span><%= f.text_field :claimantemail %></span></li>

  <li>Claimant URL<span><%= f.text_field :claimanturl %></span></li>

  <li>Comments<span><%= f.text_field :comments %></span></li>

</ul>

  <p>
    <%= f.submit "Create" %>
  </p>
<% end %><% end %>

<%= link_to 'Back', kases_path %>


I think you're getting a little confused between code that executes on the server and on the client. The content_for helper executes on the server and as you know stores a block of markup in an identifier for later use. It can appear anywhere within a view template, but its output only appears when it's yielded to in a template or a layout:

<%= yield :sidebar %>

—Wherever in the template this yield statement appears is where the markup within the content_for :sidebar block will get injected.

Remember that the form_for helper outputs an HTML form element on the client web browser and it's the other HTML elements nested within this that get submitted as part of that form. In your code above you actually have two HTML forms for cases, but only the bottom one has a button that allows you to submit it.

To have part of your form appear within the sidebar you'll have to style it to do so using CSS. So structurally the form's fields will all be within one form but visually it won't look like they are.

To have a structural separation at the markup level you'll have to use two separate forms, one of which is nested within your sidebar element and both of which have submit buttons. I doubt this is the effect you're looking for.

0

精彩评论

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