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 7858337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:23:28+00:00 2026-06-02T21:23:28+00:00

I am writing a ruby on rails 3 application that is very simple: users

  • 0

I am writing a ruby on rails 3 application that is very simple: users can create posts that display on their homepage, as well as edit these posts and delete them. My question pertains to the editing function. I know the typical way to edit something is to call

<%= link_to "edit", edit_post_path(post_item) %>

where post_item is the selected post. However, instead of redirecting the user to the edit page (/views/posts/edit.html.erb), I would like to make it so that when the user clicks the edit button, the edit page is rendered in a modal. I am using twitter-bootstrap, and know how to create modals. Any ideas?

  • 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-02T21:23:29+00:00Added an answer on June 2, 2026 at 9:23 pm

    Not sure if you’re still working on this, I had a similar problem and resolved it by doing the following:

    I’m using the jquery-ui dialog, not bootstrap modal as couldn’t make it work. so add the library there should you not have it.

    in assets/javascripts/application.js i have

    $(document).ready(function() {
    
            var modal=$('#modal');
            $('#edit_house_link').click(function(e) {
              var edit_url = $(this).attr('href'); 
              modal.load(edit_url + ' #content',function(){
                modal.dialog("open");
              });
            });
            modal.dialog({ autoOpen: false, title: "Your title", draggable: true,
            resizable: false, modal: true, width:'auto'});
    
        });
    

    then in my layouts/application.html.erb i have

    <p id="modal"></p>
    

    somewhere inside the body of the page, which is the element where we’re going to load all the info.

    in my index view i have the link that handles this, note that my model is called house, so change to whatever yours is called.

    <%= link_to 'Edit', edit_house_path(house), :remote => true, :id => 'edit_house_link' %>
    

    As you can see, i’m giving this the edit_house_link id, which I’m referencing in the application.js file.

    inside the house controller i have:

    def update
      @house = House.find(params[:id])
      respond_to do |format|
        if @house.update_attributes(params[:house])
          format.js 
        else
          format.js
        end
      end
    end
    

    and then i have three views, one is the edit.html.erb, update.js.erb and _form.html.erb for the views/houses folder.

    so inside views/houses/update.js.erb i have:

    <%- if @house.errors.any? %>
      $('#modal').html('<%= escape_javascript(render('form')) %>');
    <%- else %>
      $('#modal').dialog('close');
      $('#modal').remove();
      window.location.reload();
    <%- end %>
    

    this code is to prevent the modal from closing, should there be errors. as you can see, if no errors are present, then it closes the dialog and refreshes the page to display the changes.

    in the views/houses/edit.html.erb file this is what I have:

    <div id="content">
    <%= render :partial => 'form' %>
    </div>
    

    so if you look again at the content id in the application.js file, we’re loading this inside the modal.

    and finally the partial views/houses/_form.html.erb

    <%= simple_form_for(@house, :html => { :class => 'form-vertical' }, :remote => true) do |f| %>
    <fieldset>
        <%= f.input :address %>
        <%= f.input :postcode %>
        <%= f.input :city %>
        <%= f.input :country %>
    </fieldset>
        <div class="form-actions">
        <%= f.button :submit %>
        </div>
    <% end %>
    

    I’m using simple_form, so you can adapt to your needs by having a normal form, but i had to add the :remote => true attribute for it to actually work.

    hopefully this helps!

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

Sidebar

Related Questions

Im writing a ruby application that can post comments on behalf of the user
I am writing a ruby on rails application that has large file uploads. (20-100MB).
I am writing ruby on rails application, which will have 2 different users types
I am writing a Ruby on Rails(3) application that relies on an xml feed
Writing my first, very simple Rails application, a simple admin app to track work
I'm currently writing an application in ruby on rails that uses AWS. I see
I'm writing a non-Rails ruby application (gasp!) and would like to be able to
Background: I'm writing a 'standard' (nothing special) web application in Ruby (not Rails) and
I am working on Ruby on Rails application, with Prototype. I want to display
I am writing a web based application using Ruby on Rails. In one of

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.