Ask A Question


You’re not receiving notifications from this thread.

Opening and closing a window to a new controller/view from a different controller/view

shakycode asked in General

I'm maintaining an app and need to add a pop-up window or modal that launches from the current view but loads a separate controller/view. So far I have a link_to setup to open the controller/view in a new window/tab. But I'd really like this in a modal or pop-up window that will open on link_to and then a button on the view to close the window.

Here's my code:


 <%= link_to 'Notes', call_notes_path(, :target => "_blank", :class => 'btn btn-warning btn-small' %>


    <% @notes.each do |n| %>
      <%= n.created_at.strftime("%m/%d/%y-%H:%M") %> <%= n.message %> posted by <%= n.user.username %></br>
    <% end %>

    <%= form_for @note, :url => url_for(:controller => 'notes', :action => 'create') do |f| %>
    <%= f.text_field :message %>
    <%= f.submit %>
    <% end %>


class NotesController < ApplicationController

  def index
    @call = Call.find(params[:call_id])
    @note =
    @notes = Call.find(params[:call_id]).notes.order('created_at asc')

  def create
    @call = Call.find(params[:call_id])
    @note =[:note])
    @note.user_id =

       redirect_to call_notes_path(@call), :notice => "Note has been posted to #{@call.incident_number}"
       flash.alert = "Note was not saved or no data entered."
       redirect_to call_notes_path(@call), :notice => "Note has was not posted"

I've done some research regarding modals, but all the solutions I've found want your view code to be included in the origin controller/view space. I want to be able to call the notes#index view from within a pop-up window or modal. Then add a link to close the window after notes are done being entered.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.