2. Session 5 Recap
● User Model
● Installing Gems with Bundler
● Authentication with Devise
3. Session 5: Authentication
At present, anyone can CRUD
(Create Read Update Destroy)
Signed in Users Public
4.
5. Session 6: Stocking Fillers...
More on Assets
AJAX
Orphans!
Your very own view helper
6. The Asset Pipeline
NEW in Rails 3.1!
“A framework to concatenate and minify or
compress JavaScript and CSS assets.”
Also, enables CoffeeScript, Sass and ERB for
assets.
7. Pre-Processing in Assets
Asset helpers are available e.g.
.class { backgroundimage: url(<%=
asset_path 'image.png' %>) }
8. The Asset Pipeline: Locations
app/assets – your app's assets
vendor/assets – not maintained by you
lib/assets - maintained by you but not app specific
public/ – old skool static location
9. What assets do we have?
Rails.application.config.assets.paths
Shows assets available to application including
stuff in gems.
10. JS Assets
Go to: 127.0.0.1:3000/assets/application.js
In assets/application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
This is a sprockets manifest file.
11. CSS Assets
Go to: 127.0.0.1:3000/assets/application.css
In assets/application.css:
// *= require_self
// *= require_tree .
13. AJAX: Step 1
Add
:remote => true
to
link_to 'Destroy', station, confirm:
'Are you sure?', :method => :delete
14. AJAX: Step 2
Add id to element in view
<tr id = "station_<%= station.id %>">
Respond to javascript in controller
respond_to do |format|
format.html { redirect_to stations_url }
format.js
end
15. AJAX: Step 3
Keep id of the station to be removed.
@remove_id = @station.id
Define your response javascript: destroy.js.erb
$('#station_<%= @remove_id %>').fadeOut();