Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Failed generation of resource route for action

// description of your code here

These methods test that the routes for resources defined in routes.rb are working as expected. Call them from your functional (controller) tests.

Add the following 3 methods to test/test_helper.rb (updated for Rails 1.2.5 which no longer uses semicolons as a separator for the edit action):

# Test for routes generated by map.resource (singular).
def assert_routing_for_resource(controller, skip=[], nesting=[])
  routes = [
    ["new",'/new',{},:get], ["create",'',{},:post],
    ["show",'',{},:get], ["edit",'/edit',{},:get],
    ["update",'',{},:put], ["destroy",'',{},:delete]
    ]
  check_resource_routing(controller, routes, skip, nesting)
end
# Test for routes generated by map.resources (plural).
def assert_routing_for_resources(controller, skip=[], nesting=[])
  routes = [
    ["index",'',{},:get], ["new",'/new',{},:get], ["create",'',{},:post],
    ["show",'/1',{:id=>'1'},:get], ["edit",'/1/edit',{:id=>'1'},:get],
    ["update",'/1',{:id=>'1'},:put], ["destroy",'/1',{:id=>'1'},:delete]
    ]
  check_resource_routing(controller, routes, skip, nesting)
end

# Check that the expected paths will be generated by a resource, and that
# the expected params will be generated by paths defined by a resource.
# routes is array of [action, url string after controller, extra params].
def check_resource_routing(controller, routes, skip=[], nesting=[])
  # set a prefix for nested resources
  prefix = nesting.join('s/1/')
  unless prefix.blank?
    prefix += "s/1/"
  end
  # Add params for nested resources.
  # For each 'nest', include a ":nest_id=>'1'" param.
  params = {}
  nesting.each do |param|
    params["#{param}_id".to_sym] = '1'
  end
  # Test each of the standard resource routes.
  routes.each do |pair|
    unless skip.include? pair[0]
      assert_generates("/#{prefix}#{controller}#{pair[1]}",
        {:controller=>controller,
        :action=>pair[0]}.merge(pair[2]).merge(params), {}, {},
        "Failed generation of resource route for action #{pair[0]} /#{prefix}#{controller}#{pair[1]}")
      assert_recognizes(
        {:controller=>controller,
          :action=>pair[0]}.merge(pair[2]).merge(params),
        {:path=>"/#{prefix}#{controller}#{pair[1]}", :method=>pair[3]},
        {}, "Failed to recognize resource route for path #{pair[3]}:/#{prefix}#{controller}#{pair[1]}")
    end
  end
end





Altın Fiyatları
Revizyon ile Organize Matbaacılık Brnckvvtmllttrhaberi





This is an example snippet of code.

// description of your code here

Description of my code.

THIS IS THE HTML
// insert code here..


THIS IS THE CSS
// insert code here..


THIS IS THE JAVASCRIPT
// insert code here..

templatetag test

// description of your code here


a code snippet like that at the bottom of my templatetag file while i def with a if __name__=='__main__': .. that way I can test my tag as i work on them

template.Template("so {% load photogalleries %}") is the same in the .html as it is in Python form... it just makes it easier because you can stick the py code at the end of your template tags file and then run Wing's Debug on that file... That will allow you to set breakpoints within your tags and quickly figure out what's going on with them....


template.Template("everything in this string is treated  just like the contents of your  myfile.html template file")

template.Template("so {% load photogalleries %}"

create a template tag django

//
example of some of the stuff in ellington.core.parts.templatetags to make life easier when creating tags...

This is pretty beta, so at this point some stuff might not function as desired.. The function/model doc's in the code are ok..


*above is a 'should work' version of the tag you were talking about friday*

the above code would create a template tag {% get_gallery_list %} which takes to kwarg's .. (categories, as), categories will be passed into the GalleryByCategoryNode as is, but as will be remapped to variable_name since as is a reserved keyword in python... Your class variable self.categories__in will get turned into the galleries.get_list(categories__in=()) .. That variable name might have to be changed to self.category__slug__in, .....etc.. to work...

yeah basically it creates the whole def get_gallery_list(parser, tokens):
#.. do a bunch of argument parsing
return MyNodeClass(**kwargs)


from ellington.core.parts.templatetags import GetListNode, get_kwarg_templatetag
    class GalleryByCategoryNode(GetListNode):
    model = Gallery
    def __init__(self, categories='', variable_name='gallery_list'):
        self.categories__in = categories.split(',')


register.tag(get_kwarg_templatetag(
     name='get_gallery_list',
     doc="""Example: {% get_gallery_list categories sports,outdoors %}
        from django.core import template
        t = template.Template("{% load photogalleries %} {% get_gallery_list categories sports as      my_galleries%}{{ my_galleries }}")
     """,
     node_class=GalleryByCategoryNode,
     remap_arguments=(('as', 'variable_name'),),

Acts as Taggable on Steroids: tag cloud rhtml + view helper

// description of your code here
controller layout (base) stylesheet update
  <%= stylesheet_link_tag 'scaffold', 'tag_cloud' %>


create stylesheet, put it in ./public/, name it tag_cloud.css or similar
/* tag_cloud styles*/
.nube1 {font-size: 1.0em;}
.nube2 {font-size: 1.2em;}
.nube3 {font-size: 1.4em;}
.nube4 {font-size: 1.6em;}
.nube5 {font-size: 1.8em;}
.nube6 {font-size: 2.0em;}


partial template call
	TAG CLOUD<br/>
	<%= render(:partial => "shared/article_tag_cloud", :locals => {:tags => @tags}) %>

view template code, as a partial or within index/show action template
	<% # For our purposes, have this filter the list of articles to those with the chosen tag
		tag_cloud true, tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, css_class| %>
		<%= link_to name, tag_path(name), class => css_class # links to Tag resource, with tag name as 'id'
		%>
	<% end %>

helper code
	def tag_cloud(active, tags, classes)
		if !active then return end
		max, min = 0, 0
		unless tags.empty?
			tags.sort! {|x,y| y.count <=> x.count}
			max = tags.first.count
			min = tags.last.count			
		end
	
		divisor = ((max - min) / classes.size) + 1
	
		tags.each { |t|
			yield t.name, classes[(t.count.to_i - min) / divisor]
		}
	end

mimimee 123

// description of your code here

index.php
<html>
	<head>
		<script type="text/javascript" src="modul - clock.php"></script>
		<script type="text/javascript">
			window.onload=function(){		//functia asta porneste script-ul la incarcarea paginii.
			setInterval("displaytime()", 1000)
		}
	</script>
</head>

<body>
<?php $time = "".date("d-m-Y")."<br>".date("H:i:s").""; /*NECESAR pentru a inlocui delay-ul pana ce se incarca script-ul*/?>
<span id="clock" style="position:relative;"><?=$time;?></span>
</body>
</html>

technorati multi-word tagging bookmarklet : my custom modification

// Replace BLOGNAME with your own blog name. If input is "javascript, text snippets, code" without quotes, output is "Tags: t javascript, t text snippets, t code, t BLOGNAME" with appropriate technorati tag links. span class is tectag. To find posts tagged javascript and code in your Blogger blog, search for ("t javascript" AND "t code") without paranthesis from the Blogger search box at the top, or search for (tag:javascript tag:code) from Technorati.
// This is a compressed and modified version of the bookmarklet code at http://consumingexperience.blogspot.com/2005/07/technorati-tag-creator-for-multiple.html

javascript:(
function(){
var a='<span class=\"tectag\"> <b>Tags</b>: ';
var t=prompt('enter:','')+', BLOGNAME';
var tr=t.split(',');
for(var i=0;i<tr.length;i++){
	if(i>0){a+=', ';}
	tr[i]=tr[i].replace(/^\s*|\s*$/g,'');
	a+='t <a href=\"http://technorati.com/tags/'+tr[i].replace(/\s/g,'+')+'\" rel=\"tag\">'+tr[i]+'</a>';
}
prompt('copy:',a+'</span>');
}
)()