An open API service indexing awesome lists of open source software.

https://github.com/amiel/can_haz_modal

Ruby on Rails plugin to automatically render without a layout on certain requests
https://github.com/amiel/can_haz_modal

Last synced: 11 months ago
JSON representation

Ruby on Rails plugin to automatically render without a layout on certain requests

Awesome Lists containing this project

README

          

Can Haz Modal
=============

Requests with the format of :partial will now render with no layout
The format will be adjusted back to :html so that your html views will be rendered even when the :partial format is specified

Two things you will need to do to take advantage of this plugin:

1. add :format => :partial to links that you want to open in a modal

Example: new_user_session_path(:format => :partial)

2. Setup some sort of modal javascript library and make it open for links that end with .partial

Here is an example using jQuery and Boxy:

$('[href$=.partial]').boxy();

3. Profit

Rails 3
=======

This plugin has not been ported to rails 3 yet. I promise I'll get to it soon.

In the mean time, it's really easy to just copy over the bits you need:

Add the mime type to your initializers (config/initializers/mime_types.rb):

Mime::Type.register_alias 'text/html', :partial

Put this in your ApplicationController:

before_filter :adjust_format_for_partial
layout :no_layout_for_xhr
helper_method :is_partial?

private
def no_layout_for_xhr
is_partial? ? nil : 'application'
end

def adjust_format_for_partial
if request.format == :partial then
@__partial = !!request.xhr?
request.format = :html # reset format to html so that people don't have to rename their view files
else
@__partial = false
end
end

def is_partial?
@__partial
end

Copyright (c) 2010 Amiel Martin, Carnes Media, released under the MIT license