Skip to content

Instantly share code, notes, and snippets.

@boy-jer
boy-jer / route.js
Created April 24, 2013 20:05 — forked from darthdeus/route.js
Scvrush.UserEditRoute = Ember.Route.extend({
events: {
saveProfile: function() {
var user = this.controllerFor("user").get("content"),
route = this;
user.one("didUpdate", function() {
route.transitionTo("home");

Rollback a transaction when user exits a route

I just stubmled upon an issue in my app where a user can go to edit his profile, but instead of saving the form he just leaves to another page where he can post a status (User has many Statuses).

But to make sure that he's just posting a status and not committing something else I want to put that status into a separate transaction

createStatus: function() {
  var transaction = this.get("store").transaction(),
      text = this.get("text"),

Rollback a transaction when user exits a route

I just stubmled upon an issue in my app where a user can go to edit his profile, but instead of saving the form he just leaves to another page where he can post a status (User has many Statuses).

But to make sure that he's just posting a status and not committing something else I want to put that status into a separate transaction

createStatus: function() {
  var transaction = this.get("store").transaction(),
      text = this.get("text"),
authenticated :user do
root to: "agendas#show"
end
unauthenticated :user do
devise_scope :user do
root to: "devise/sessions#new"
end
end
template = template.replace(/@(\w+)/, "{{view Scvrush.UserLinkView username='$1'}}");
usernames = template.match(/@(\w+)/);
controllerFor('controllerWithText').set('usernames', usernames);
Scvrush.ControllerWithText = Em.Controller.extend({
init: function() {
var usernames = this.get('usernames'),
loadedusers = Scvrush.User.all();
App.PostsController = Em.ArrayController.extend({
page: 1,
content: function loadPosts() {
return App.Post.filter({page: 1}, function() {});
}.property(),
loadMore: function() {
App.Post.find({page: this.incrementProperty('page')})
}
DS.Model.reopenClass({
scope: function(name, fn) {
Ember.defineProperty(this, '_'+name+'Filter', Ember.computed(function() {
return this.filter(fn);
}));
Ember.defineProperty(this, name, Ember.computed('_'+name+'Filter.@each.id', function() {
return this.get('_'+name+'Filter')
}));
1.upto(100) do |i|
puts ''.tap {|output|
output << 'Fizz' if i.modulo(3).zero?
output << 'Buzz' if i.modulo(5).zero?
output << i.to_s if output.empty?
}
end
#custom initializer, that automagically loads all processors
# initializer is required to load additional preprocessors for carrierwave - Rails will not load them for you.
dir = Rails.root.join('lib', 'carrierwave_processing')
$LOAD_PATH.unshift(dir)
Dir[File.join(dir, "*.rb")].each {|file| require File.basename(file) }
#And that's it - from this moment on your app will be able to convert uploaded video files to "displayable" format.
##I hope that above solution will save you some time.
Adapted from Tchak's code here https://gist.github.com/4511824
//Passing a function instead of route name will setup an anonymous route and assign the function as `redirect` hook.
//Passing object instead of route name can be used to redirect for example.
App.Router.map(function {
this.resource('index', { path: '/'}, function() {
if (this.controllerFor('login').get('isSignedIn')) {
this.transitionTo('search');
} else {
this.transitionTo('signIn');