简体   繁体   中英

Unable to render form inside twitter bootstrap modal?

I am trying to use a modal in my ruby on rails application.using twitter-bootstrap-rails.

My Code

In my page where i am using modal is (view/auth/main/)

<a href="#sneh"role="label" class="link" data-toggle="modal">Add Asset</a>
<div id="sneh" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add Asset</h3>
</div>
<div class="modal-body">
    <p>
     <%= render "vendors/new" %>
    </p>
    </div>
  </div>

I have a vendors controller have new.html.erb page. And in new.html.erb

   <%= form_for(@vendor) do |f| %>
      <table width="700">
        <tr>
          <td>
            <%= f.label :Full_name %>
            <h3><i class="fa fa-user"></i>
              <%= f.text_field :name %>
            </h3>
          </td>
           <td>
            <%= f.label :address %><h3><i class="fa fa-align-justify"></i> 
            <%= f.text_area :address %></h3>
          </td>
        </tr>
          <tr>
            <td>

             <%= f.label :email %><h3><i class="fa fa-envelope"></i>
             <%= f.text_field :email %></h3>
           </td>
             <td>

              <%= f.label :location %><h3><i class="fa fa-map-marker"></i>
              <%= f.text_field :location %></h3>
            </td>
          </tr>
          <tr>
            <td>

             <%= f.label :ph_no %><h3><i class="fa fa-phone"></i>
             <%= f.text_field :ph_no %></h3>
           </td>
             <td>

              <%= f.label :mobile_no %><h3><i class="fa fa-phone-square"></i>
              <%= f.text_field :mobile_no %></h3>
            </td>
          </tr>
          <tr>
            <td>

              <%= f.label :asset_name %><h3><i class="fa fa-truck"></i> 
              <%= f.text_field :asset_name %></h3>
            </td>
          <td>
                  <%= f.submit "Save", class: "btn  btn-primary btn-lg btn3d" %>
                  <%= f.submit "Cancel",  class: "btn btn-danger btn-lg btn3d" %>
                </td>
                </tr>
                </table>

After adding the render command i get the error such as ActionView::MissingTemplate in Auth#main And when i remove that and write the form in html it works, but what to do if i want to do the same in rails..thanks.:)

You can create a partial lets '_form.html.erb '. Put all the content of the new.html.erb in it.

In the new.html.erb,

<%= render "/vendors/form" %>

In the modal also use the same.

<%= render "/vendors/form" %>

After creating the partial _form.html.erb . The error is in the controller auth controller.rb changes you should made in auth controller.rb

def main
  @vendor = Vendor.new
end
def create
    @vendor = Vendor.new(params[:vendor])
        if @vendor.save
            flash[:success] = "Vendor Added Successfully"
            render @vendor
        end
  end
  def show
@vendor = Vendor.find(params[:id])

@title = @vendor.name
end

This will save into your data base. thank you.

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