Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:38:48+00:00 2026-06-02T12:38:48+00:00

On Rails 3.2.3, I have a form in a partial view, using bootstrap 2.0.2

  • 0

On Rails 3.2.3,
I have a form in a partial view, using bootstrap 2.0.2 modals

#myModal.modal
  .modal-header
    .close{"data-dismiss" => "modal"}= link_to "x", root_path
    %h3 Add Tags
  .modal-body
    = form_tag '/tagging', :remote => true do
      = text_field_tag 'tags_string', params[:tags_string]
      = hidden_field_tag 'id', params[:id]
      .modal-footer
        = submit_tag "Add tag", :class => "btn btn-primary"
  :javascript
    $(document).ready(function() {
      $('#myModal .btn.btn-primary').click(function() {
        $('#myModal').modal('hide');
        $('form').submit();
      });
    });

I the “main” page I’ve a link button to call the partial :

%td= link_to "Tag", tagging_path(:id => "#{repo.id}", :tags_string => "#{repo.tags}"), "data-toggle" => "modal", :class => "tag add-tag btn btn-primary

and the controller has the relative tagging method.

Now I have two problems:

  1. first

    when I click the button it display the form correctly but it leaves
    the “main” page (which I don’t want), displaing the relative href
    (which is empty), as a background :

    http://localhost:3001/tagging?id=4f82cb8ef370ff0001000699&tags_string=
    

    that is generated by the ‘tagging_path’ in the link button. I cannot
    just call the modal like in bootstrap example :

    <a data-toggle="modal" href="#myModal" class="btn btn-primary btn-large">Launch demo modal</a>
    

    because I need to fill the controller/model with form params so …,
    how can this be done ?

  2. second:

    when I click the “Add tag” button in the form, the database get the
    right content and everything works but the form doesn’t disapear
    until I click “X” link, which is just a link to root_path and not a JS action.

    so it seems js is not working properly

    $(document).ready(function() {
      $('#myModal .btn.btn-primary').click(function() {
        $('#myModal').modal('hide');
        $('form').submit();
      });
    });
    

UPDATE:

This is the generated html :

<div class='modal hide fade' id='myModal'>
    <div class='modal-header'>
        <div class='close' data-dismiss='modal'><a href="/">x</a></div>
            <h3>Add Tags</h3>
        </div>

        <div class='modal-body'>
        <form accept-charset="UTF-8" action="/tagging" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" />
                <input name="authenticity_token" type="hidden" value="vlZaCIRV58BfDZ0xjYsefSEVL1LSpiI5UL1tgzbm/8o=" /></div>
            <input id="tags_string" name="tags_string" type="text" />
            <input id="id" name="id" type="hidden" />

            <div class='modal-footer'>
            <input class="btn btn-primary" name="commit" type="submit" value="Add tag" />
            </div>
        </form>
    </div>
</div>

<td>
    <a href="/tagging?id=4f82cb5cf370ff000100003a&amp;tags_string=ruby+web+framework" class="tag add-tag btn btn-primary" data-toggle="modal">Tag</a></td>
</tr>
<tr>
<td>
    <div class='gravatar'><img alt="Assets.github.com%2fimages%2fgravatars%2fgravatar-orgs" height="26" src="https://secure.gravatar.com/avatar/b0f9595244db739302ccce55bfbfc5e5?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png" width="26" /></div>
</td>
<td>
    <a href="https://github.com/h5bp/html5-boilerplate">h5bp/html5-boilerplate</a>
</td>
<td class='watchers span1'>12105</td>
<td class='forks span1'>1781</td>
<td>A professional front-end template that helps you build fast, robust, adaptable, and future-proof websites.</td>
<td>Sun, Jan 24 at  6:03pm</td>
<td>Sat, Apr 14 at  2:10pm</td>

...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:38:51+00:00Added an answer on June 2, 2026 at 12:38 pm

    1) Use event.preventDefault() to stop the link action

    2) Your selector needed a space. Or you can just leave .btn out entirely.

    $(document).ready(function() {
        $('#myModal .btn-primary').click(function(e) {
            e.preventDefault();
            $('#myModal').modal('hide');
            $('form').submit();
        });
    });
    

    If you post the rendered HTML markup of your modal I can help with your selector since using the class is generally not a good idea if you want to capture a specific button click.

    Edit given markup:

    Okay, you can just make your button a button type instead of submit and select it by its name instead. If you use a submit you don’t need to call form.submit, it does that by default. Using a button type gives you more control.

    $('input[name="commit"]').click(function() {
        //$('form').submit();
        $('#myModal').modal('hide');        
    });
    

    Working example: http://jsfiddle.net/tcjCj/3/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large Ruby on Rails form that has the following partial view
I would like to have Ajax form in Rails so i'm using form_remote_tag. The
this time it's about Ruby On Rails. I have a form in the view
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
I have a nested form in a rails view that is called like this
rails: I have 'create' and 'update' using the same partial '_form' but the url
I have a rails form with a datetime_select field. When I try to submit
I have a Rails form for email, and I would like to have auto-completion
I have a live rails website and I want to have a form with
In my Rails app, I have a form which redirects through a foreign service,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.