document.write("<div class=\"pastie\">\n");
document.write("  <link href=\"http://pastie.org/stylesheets/embed.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n");
document.write("  <link href=\"http://pastie.org/stylesheets/clean.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n");
document.write("  \n");
document.write("\n");
document.write("  \n");
document.write("  \n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("	\n");
document.write("	<div class=\"allcode\">\n");
document.write("		<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");
document.write("		<tr>\n");
document.write("			<td>\n");
document.write("				\n");
document.write("				<pre class=\"textmate-source-numbers\">1\n");
document.write("2\n");
document.write("3\n");
document.write("4\n");
document.write("5\n");
document.write("6\n");
document.write("7\n");
document.write("8\n");
document.write("9\n");
document.write("10\n");
document.write("11\n");
document.write("12\n");
document.write("13\n");
document.write("14\n");
document.write("15\n");
document.write("16\n");
document.write("17\n");
document.write("18\n");
document.write("19\n");
document.write("20\n");
document.write("21\n");
document.write("22\n");
document.write("23\n");
document.write("24\n");
document.write("25\n");
document.write("26\n");
document.write("27\n");
document.write("28\n");
document.write("29\n");
document.write("30\n");
document.write("31\n");
document.write("32\n");
document.write("33\n");
document.write("<\/pre>\n");
document.write("			<\/td>\n");
document.write("		<td>\n");
document.write("		<pre class=\"textmate-source\"><pre class=\"sunburst\"><span class=\'meta meta_rails meta_rails_model\'><span class=\'meta meta_class meta_class_ruby\'><span class=\'keyword keyword_control keyword_control_class keyword_control_class_ruby\'>class<\/span> <span class=\'entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby\'>Book<span class=\'entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby\'> &lt; ActiveRecord::Base<\/span><\/span><\/span>\n");
document.write("\n");
document.write("  <span class=\'support support_function support_function_activerecord support_function_activerecord_rails\'>validates_presence_of<\/span> <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:title<\/span>\n");
document.write("  <span class=\'support support_function support_function_activerecord support_function_activerecord_rails\'>has_and_belongs_to_many<\/span> <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:authors<\/span>, <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:join_table<\/span> =&gt; <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;books_authors&quot;<\/span>, <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:order<\/span> =&gt; <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;authors.name&quot;<\/span>\n");
document.write("  <span class=\'support support_function support_function_activerecord support_function_activerecord_rails\'>has_and_belongs_to_many<\/span> <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:tags<\/span>, <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:order<\/span> =&gt; <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;tags.name&quot;<\/span>\n");
document.write("  <span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>attr_accessor<\/span> <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:authors_s<\/span>, <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:tags_s<\/span>\n");
document.write("  <span class=\'support support_function support_function_activerecord support_function_activerecord_rails\'>before_save<\/span> <span class=\'constant constant_other constant_other_symbol constant_other_symbol_ruby\'>:process_attributes<\/span>\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>  # lookup authors_s and tags_s<\/span>\n");
document.write("  <span class=\'meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby\'><span class=\'keyword keyword_control keyword_control_def keyword_control_def_ruby\'>def<\/span> <span class=\'entity entity_name entity_name_function entity_name_function_ruby\'>after_find<\/span><\/span>\n");
document.write("    <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.authors_s <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.authors.collect {<span class=\'meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block\'> <\/span>|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>author<\/span>| author.name }.join(<span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;, &quot;<\/span>)\n");
document.write("    <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.tags_s <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.tags.collect {<span class=\'meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block\'> <\/span>|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>tag<\/span>| tag.name }.join(<span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;, &quot;<\/span>)\n");
document.write("  <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("\n");
document.write("  <span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>private<\/span> \n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>    # process authors and tag attributes for allow use of strings and arrays<\/span>\n");
document.write("    <span class=\'meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby\'><span class=\'keyword keyword_control keyword_control_def keyword_control_def_ruby\'>def<\/span> <span class=\'entity entity_name entity_name_function entity_name_function_ruby\'>process_attributes<\/span><\/span>\n");
document.write("      <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.authors <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> array_to_string(<span class=\'variable variable_language variable_language_ruby\'>self<\/span>.authors_s, <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;Author&quot;<\/span>) <span class=\'keyword keyword_control keyword_control_ruby\'>unless<\/span> <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.authors_s.nil?\n");
document.write("      <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.tags <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> array_to_string(<span class=\'variable variable_language variable_language_ruby\'>self<\/span>.tags_s, <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;Tag&quot;<\/span>) <span class=\'keyword keyword_control keyword_control_ruby\'>unless<\/span> <span class=\'variable variable_language variable_language_ruby\'>self<\/span>.tags_s.nil?\n");
document.write("    <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>    # convert string elements split by \',\' to objects (create if needed)<\/span>\n");
document.write("    <span class=\'meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby\'><span class=\'keyword keyword_control keyword_control_def keyword_control_def_ruby\'>def<\/span> <span class=\'entity entity_name entity_name_function entity_name_function_ruby\'>array_to_string<\/span>(<span class=\'variable variable_parameter variable_parameter_function variable_parameter_function_ruby\'>string_array, model_name<\/span>)<\/span>\n");
document.write("      model_array <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> []\n");
document.write("      model_object <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'support support_class support_class_ruby\'>Object<\/span>.const_get(model_name)\n");
document.write("      string_array.split(<span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;,&quot;<\/span>).each <span class=\'keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby\'>do <\/span>|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>name<\/span>|\n");
document.write("        model_array <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby\'>&lt;&lt;<\/span> model_object.find_or_create_by_name(name.strip)\n");
document.write("      <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("      model_array\n");
document.write("    <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("\n");
document.write("<\/span><span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("<\/pre><\/pre>\n");
document.write("		<\/td>\n");
document.write("		<\/tr>\n");
document.write("		<\/table>\n");
document.write("	\n");
document.write("	<\/div>\n");
document.write("\n");
document.write("\n");
document.write("  \n");
document.write("  \n");
document.write("  <div class=\"credit\">\n");
document.write("    <div class=\"buttons\">\n");
document.write("      <a href=\"http://pastie.org/pastes/842144.txt\">\n");
document.write("      <img src=\"http://pastie.org/images/view.png\" height=\"20\" width=\"67\" /><\/a>\n");
document.write("    <\/div>\n");
document.write("  \n");
document.write("    <a href=\"http://pastie.org/842144\">Pastie #842144<\/a> linked directly from <a href=\"http://pastie.org/\">Pastie<\/a>.\n");
document.write("  <\/div><\/div>");

