The goal of rails is to make easy a full customizable ajax experience within a rails application, managing:
- ajax calls
- flash messages
- redirect_to
- deep linking
- browser history
- page title
Add this line to your application's Gemfile:
gem "railx", :git => "https://github.com/sekipaolo/railx.git"
And then execute:
$ bundle install
Add following lines to your app/assets/javascripts/application.js
//= require railx
then in app/assets/stylesheets/application.css
*= require railx
*/
Now all your links will trigger an ajax call, filling the body with the content of the response.
You can configure a default target for all links in your javascript files in this way:
window.Railx.default_target = "#container"
or specify it on Html side
<a href="some_url" data-target="#left-div"> Link </a>
from a controller you can update the content of mor divs other than the main content.
def index
# do something
updatediv "#header", "layouts/header"
respond_to do |format|
format.html # index.html.erb
format.json { render json: @feeds }
end
end
the target div will be filled with the content of index.html.erb and the div with id "header" with the content of partial layouts/_header.haml (or erb or other formats)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request