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
- Host: GitHub
- URL: https://github.com/amiel/can_haz_modal
- Owner: amiel
- License: mit
- Created: 2010-07-29T22:42:39.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2010-09-30T19:01:20.000Z (over 15 years ago)
- Last Synced: 2024-10-03T12:33:15.569Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 93.8 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: MIT-LICENSE
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