Skip to content

Instantly share code, notes, and snippets.

View almaron's full-sized avatar

Ilya Levin almaron

View GitHub Profile
def get_topic
@topic = ForumTopic.find(params[:id])
unless @topic
respond_to do |format|
format.html { redirect_to forum_path(params[:forum_id]) }
format.json { render json: {redirect: forum_path(params[:forum_id])}, status: 500 }
end
end
end
$scope.$watch "postPagination.cur", (newVal) ->
if angular.isDefined newVal && newVal
$scope.loadPosts newVal
$window.history.pushState({},"",$scope.currentPath+"?page="+newVal)
$anchorScroll()
$scope.$watch "postPagination.cur", (newVal) ->
if typeof newVal != "undefined" && newVal
console.log newVal
$scope.loadPosts newVal
$window.history.pushState({},"",$scope.currentPath+"?page="+newVal)
$anchorScroll()
app.filter("filterTree", [
"$filter", function($filter) {
return function(tree) {
var newTree = [];
angular.forEach(tree, function(node, index) {
var newNode;
newNode = {
id: node.id,
sort_order: index,
children: $filter('filterTree')(node.children)
[
{
"id": 1,
"sort_order":0,
"children": [
{
"id": 3,
"sort_order":0,
"children": [
{
[
{
"id": 1,
"name": "Игровой раздел",
"hidden": 0,
"technical": 0,
"is_category": 1,
"image": null,
"description": null,
"isCategory": true,
<!--
If I have a $scope.links array how do I make this in angular?
-->
<a href="/links/linkl_head">link1_link</a>, <a href="/links/link2_head">link2_link</a>, <a href="/links/link3_head">link3_link</a>, <a href="/links/link4_head">link4_link</a>, <a href="/links/link5_head">link5_link</a>
@almaron
almaron / gist:5739bfb6acc9a05b79a6
Created June 10, 2014 11:04
Can anyone help me simplify this?
#forum.rb
def get_all_posts
forums = self.subtree_ids
topics = Topic.where(forum_id: forums).collect(&:id)
posts = Post.where(topic_id: topics)
end
# Forum has_many :topics and has_ancestry
# Topic has_many :posts
@app.factory "News", ["$resource", ($resource) ->
$resource("/news/:id.json",{id: '@id'}, {update: {method: "PUT"}, get_total:{method:"GET", params:{get_total:true}}})
]
@app.controller 'NewsCtrl', ["$scope", "$location", "News", ($scope, $location, News) ->
$scope.loadSomeNews = (number) ->
$scope.news = News.query {limit: number}
$scope.pagination = { }
$scope.initNews = (page = 1) ->
$scope.pagination.cur = page
$scope.getTotal()