Ask A Question

Notifications

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:

calls/index.html.erb

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

notes/index.html.erb

    Notes:</br>
    <% @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 %>

controllers/notes_controller.rb

class NotesController < ApplicationController

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

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

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

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.

Reply
Join the discussion
Create an account Log in

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

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

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