Skip to content

Instantly share code, notes, and snippets.

@zeromodulus
zeromodulus / gist:8140860
Created December 27, 2013 00:42
This code would generate routes such as /admin/posts and /blog/posts. However, they both map to the same controller, PostsController. Is this the 'correct' way? How do I differentiate between how the request came in, from in PostsController? That is, how do I tell which route the request came in through?
resource :admin do
resources :posts
end
resource :blog do
resources :posts
end
Vim: Caught deadly signal SEGV3C
Vim: Finished.
Segmentation fault (core dumped)
import os
from mediabox.settings import *
SITE_ID = 1
PROJECT_ROOT = os.getcwd()
DEBUG = True
TEMPLATE_DEBUG = DEBUG
{
:user_panel => [],
:main => [
{:text => "Recipes", :path => app.recipes_path, :submenus => {
:index => [
{:text => "Newest", :path => app.newest_recipes_path},
{:text => "Oldest", :path => app.oldest_recipes_path},
{:text => "Most Favored", :path => app.most_favored_recipes_path},
{:text => "Most Viewed", :path => app.most_viewed_recipes_path}
],
from django.db import models
from django.dispatch import receiver
from django.db.models.signals import pre_save
class Post(models.Model):
title = models.CharField(unique=True, max_length=1024)
slug = models.CharField(unique=True, max_length=1024)
@receiver(pre_save)
def create_slug(sender, instance, *args, **kwargs):
/home/zero/.envs/default/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/home/zero/.envs/default/bin/python and that PATH is
set properly.
/home/zero/.envs/default/bin/python: No module named virtualenvwrapper
/home/zero/.envs/default/bin/python: No module named virtualenvwrapper
<%= link_to @nested_instance.title,
something_url(
:parent_namespace_id => @parent_namespace_thing,
:id => @nested_instance.id,
:anchor => :foo
)
%>
# On User (the only association I'm having an issue with):
# This model is at the top level, i.e. it is not namespaced
# as Recipes::Recipe and Recipes::Favorite are namespaced.
has_many :favorite_recipes,
:class_name => 'Recipes::Recipe',
:foreign_key => :recipe_id,
:source => :recipe,
:through => :favorites # The model for this is actually Recipes::Favorite
def self.get_sorted(sort_by)
recipes = nil
heading = nil
case sort_by
when "new", nil
heading = "viewing newest recipes."
recipes = Recipe.order("created_at DESC")
when "old"
heading = "viewing oldest recipes."
# Test
test "should delete destroy" do
user = FactoryGirl.create(:user)
sign_in user
recipe = FactoryGirl.create(:recipe)
photo = FactoryGirl.create(:photo)
recipe.photos << photo
recipe.save