This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RecipesController < ApplicationController | |
| ... | |
| def new | |
| @recipe = Recipe.new | |
| end | |
| def create | |
| @recipe = Recipe.new(params[:recipe]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create | |
| @recipe = Recipe.new(params[:recipe]) | |
| if @recipe.save | |
| flash[:notice] = 'Recipe was successfully created.' | |
| redirect_to recipes_path | |
| else | |
| flash[:error] = 'The recipe failed to save.' | |
| render :action => 'new' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function slugify(str) { | |
| return str.toLowerCase(). | |
| replace(/&/g, 'and'). | |
| replace(/[^a-z0-9']+/g, '-'). | |
| replace(/^-|-$/g, ''); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Page < ActiveRecord::Base | |
| acts_as_tree | |
| def self.tree | |
| hash = find(:all).inject({}) { |hash, p| hash[p.id] = [p, []]; hash } | |
| hash.inject([]) { |result, (key, value)| | |
| if parent_id = value.first.parent_id | |
| hash[parent_id].last << value | |
| else | |
| result << value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.ajaxSetup({ | |
| data: { authenticity_token: AUTHENTICITY_TOKEN }, | |
| beforeSend: function(xhr) { | |
| xhr.setRequestHeader("Accept", "text/javascript") | |
| } | |
| }); |
NewerOlder