5. Gems supposed to
be well understood
• jquery-rails
• anjlab-bootstrap-rails
• simple_form
• carrierwave
• mini_magick / rmagick
6. Ground rails project
• Have two models associated with has_many
• Have one model mounted with carrierwave’s
uploader
• Render 'form' in views of new and edit
• Use respond_with for each action of controller
• Layout with twitter bootstrap
10. creatures_controller.rb
class CreaturesController < ApplicationController
before_filter :load_creature, only: [:show, :edit, :update, :destroy]
respond_to :html
def edit
render 'edit_modal', layout: false if request.xhr?
end
def update
@creature.update_attributes params[:creature]
if @creature.valid?
flash[:notice] = 'Creature was successfully updated.'
end
respond_with @creature do |format|
format.html {
if @creature.valid?
load_creatures
render partial: 'table', locals: { creatures: @creatures }
else
render 'edit_modal', layout: false
end
} if request.xhr?
end
flash.discard :notice if request.xhr?
end
end
18. Key Points
• Use respond_with
• Render 'modal' specific files
• Render partial files
• Via data attributes
• Define rails ajax callbacks
• Use namespace for javascript methods
• Catch ajax callback in div container if data-type
is :html