简体   繁体   中英

Updating params with a value from a form within a modal

I have been searching for an answer to this online, but because I'm new to rails none of the answers have been easy enough for me to understand.

I have a few forms within a modal popup that I'd like to get information from into a controller. I'm using Foundation to create the form, and the html is as follows:

<form>
  <div class="row">
    <div class="small-8 columns">
      <div class="row">
        <div class="small-3 columns">
          <label for="right-label" class="right inline">Name</label>
        </div>
        <div class="small-9 columns">
          <input name="input1" type="text" id="right-label" placeholder="Full name here">
        </div>
      </div>
    </div>
  </div>
  </form>

I would like to get the value from input1 into a controller to play around with or add to my database, and I was wondering if anyone could give a good explanation for the best way to go about this, or provide a link to a good explanation as to how I do this. Is it good practice to add these values to my params and then access it from the controller? That was what I initially thought would be a good idea, but I can't even seem to figure that out.

Thanks.

To combine Rails with Foundation, you need to modify it like the following:

<%= form_for @name_of_object_declared_in_your_controller_for_this_action do |f| %>
  <div class="row">
    <div class="small-8 columns">
      <div class="row">
        <div class="small-3 columns">
          <%= f.label :input1 %>
        </div>
        <div class="small-9 columns">
          <%= f.text_field :input1, placeholder: 'Full name here' %>
        </div>
      </div>
    </div>
  </div>
<% end %>

For more information about implementing forms in Rails, I would suggest reading the Rails Guide for Form Helpers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM