Created
October 15, 2013 16:07
-
-
Save adambeynon/6994021 to your computer and use it in GitHub Desktop.
vienna + rails = <3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We want vienna to render our Product#show view... | |
class ProductController < ApplicationController | |
def show | |
@product = Product.find(...) | |
render :vienna => @product | |
end | |
end | |
# The `vienna` renderer will look for a view (Vienna::View) subclass that | |
# is named ShowProductView. The `@product` ivar will be set in that view. | |
# We then render the views/product/show.erb file in the context of our | |
# ShowProductView | |
class ShowProductView < Vienna::View | |
def nicer_title | |
@product.title + " is really awesome!" | |
end | |
end | |
# show.erb: | |
# | |
# <h1><%= nicer_title %></h1> | |
# Now, the awesome bit! When our html page loads, we will have an instance of | |
# ShowProductView running on the client, with the @product ivar already setup! | |
# So, we can then just use the #after_render hook to do some stuff. | |
class ShowProductView < Vienna::View | |
def nicer_title | |
@product.title + " is really awesome!" | |
end | |
def after_render | |
@element.on(:click, '.title') do |evt| | |
alert "did you like the title? #{nicer_title}" | |
end | |
end | |
end | |
# ALSO, our events will be setup as well :) | |
class ShowProductView < Vienna::View | |
def nicer_title | |
@product.title + " is really awesome!" | |
end | |
on :click, '.title' do |evt| | |
alert "did you like the title? #{nicer_title}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment