Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Documentation on mustache Lambdas #4

Closed
maxstudener opened this Issue · 7 comments

2 participants

@maxstudener

http://mustache.github.com/mustache.5.html shows how in javascript you can you return a function but how does rails call it.

For example im using faye to broadcast a private message, i want javascript to run a function called check_acces and i want rails to run a function called check_acces when the page is reloaded

@le0pard
Owner

You can use Proc.new or lambda.

@le0pard
Owner

Example:

   a = {
      url: product_url(product),
      title: product.title,
      price: number_to_currency(product.price),
      description: product.description,
      test_info: Proc.new { 2 + 2 }
    }
   <%= render "products/product", mustache: a %>
@maxstudener

what im trying to is something like this

can_edit: Proc.new {user == current_user}

that works for a render, but not when i publish the result to subscribers, id need javascript end to execute the proc too

@le0pard
Owner
var a = {
  title: "title",
  can_edit: function(){
    // do something
  }
}
SMT["template"](a)

The same for js - use js function.

@maxstudener

i see my issue i was trying to make my a ={} return a function that render and a call via ajax json request could both use but that doesn't actually make sense i just need to recode the proc in both the ruby and javascript, this was uber helpful

@le0pard
Owner

Perfect. So Can I close issue?

@maxstudener

yup although it would be nice to see it in the readme but this issue is closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.