AjaxRender
Simplify your ajax implementation
Before
If you implement ajax with no plugin, you may write code as follows
# app/controllers/tests_controller.rb
class TestsController < ApplicationController
def ajax_action
@value = params[:value]
respond_to do |format|
format.js
end
end
end
<%# app/views/tests/ajax_action.js.erb %>
$('.some_element').html(<%= render '/tests/partial', locals: { value: @value } %>);
After using AjaxRender
You can avoid creating such js in your views directory by AjaxRender
# Gemfile
gem 'ajax_render'
# app/controllers/tests_controller.rb
class TestsController < ApplicationController
def ajax_action
ajax_render '/tests/partial', replace: '.some_element', locals: { value: params[:value] }
end
end
Contributing
- 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