This file contains 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 children(logged_in = true) | |
if logged_in | |
account.pages.where(parent_id: self.id) | |
else | |
account.pages.where(parent_id: self.id, is_active: true) | |
end | |
end | |
@page.children(logged_in?) |
This file contains 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
#PagesController | |
def update | |
@page = current_account.pages.find(params[:id], :readonly => false) | |
@page.update_attributes(params[:page]) | |
end | |
#Page | |
before_update :change_positions, :if => :position_changed? | |
def change_positions |
This file contains 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
# Scenario: Edit exsisting theme # features/admin_manage_themes.feature:15 | |
# Given I already have a theme for the website # features/step_definitions/admin_manage_themes_steps.rb:27 | |
# When I go to the edit theme page # features/step_definitions/admin_manage_themes_steps.rb:31 | |
# And I modify the theme settings # features/step_definitions/admin_manage_themes_steps.rb:35 | |
# Couldn't find Theme with ID=551 [WHERE ("themes".account_id = 1326)] (ActiveRecord::RecordNotFound) | |
# ./app/controllers/themes_controller.rb:25:in `update' | |
# <internal:prelude>:10:in `synchronize' | |
# (eval):2:in `click_button' | |
# ./features/step_definitions/form_steps.rb:10:in `/^I submit the "(\S+)" form$/' | |
# features/admin_manage_themes.feature:18:in `And I modify the theme settings' |
This file contains 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
theme = Factory.build(:theme) | |
temp_file = Tempfile.new('prefix', "#{Rails.root}/tmp") | |
temp_file << theme.html | |
temp_file.flush | |
theme.html = temp_file |
This file contains 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
import sublime, sublime_plugin | |
import os | |
class DetectFileTypeCommand(sublime_plugin.EventListener): | |
""" Detects current file type if the file's extension isn't conclusive """ | |
""" Modified for Ruby on Rails and Sublime Text 2 """ | |
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """ | |
def on_load(self, view): | |
filename = view.file_name() |
This file contains 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
# spec/controllers/users_controller_spec.rb | |
# ERROR: | |
# Failure/Error: get :edit, :id => user.id | |
# ActionController::RoutingError: | |
# No route matches {:id=>1, :controller=>"users", :action=>"edit"} | |
describe UsersController do | |
render_views | |
it "renders edit template for edit action" do | |
user = Factory(:user) |
This file contains 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
# app/validators/domain_validator.rb | |
require "resolv" | |
class DomainValidator < ActiveModel::EachValidator | |
def validate_each(object,attribute,value) | |
begin | |
domain = Resolv::DNS.new.getresource(value, Resolv::DNS::Resource::IN::CNAME) | |
valid = true if domain.name.to_s == "mydomain.com" | |
rescue Exception => e | |
valid = false | |
end |
This file contains 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
# ERROR: | |
# _form.html.haml:25: syntax error, unexpected keyword_ensure, expecting keyword_end | |
# ...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer.... | |
# ... ^ | |
# _form.html.haml:28: syntax error, unexpected $end, expecting keyword_end | |
# | |
# _form.html.haml:28: syntax error, unexpected $end, expecting keyword_end | |
# | |
= form_for([:admin, @stencil]) do |f| |
This file contains 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
# MODELS: | |
class Stencil < ActiveRecord::Base | |
has_one :stencil_config, :dependent => :destroy | |
accepts_nested_attributes_for :stencil_config | |
end | |
class StencilConfig < ActiveRecord::Base | |
belongs_to :stencil | |
end |
NewerOlder