Skip to content

Instantly share code, notes, and snippets.

@telagraphic
telagraphic / authorization rules
Created December 5, 2011 18:16
Declarative Authorization Problem!
authorization do
role :admin do
has_permission_on [:project, :ticket, :comment, :user], :to => [:index, :show, :new, :create, :edit, :update, :destroy]
end
role :moderator do
has_permission_on :project, :to => []
has_permission_on :project, :to => []
has_permission_on :ticket, :to => [:destroy]
end
<section class="comments">
<h2>Post A Comment</h2>
<%= form_for([@post, @comment]) do |comment| %>
<%= comment.label :email %><br/>
<%= comment.text_field :email %><br/>
<%= comment.label :body %><br/>
<%= comment.text_area :body, :size => "60x12" %><br/>
<%= comment.submit "Shout out" %>
@telagraphic
telagraphic / show.html.erb
Created August 16, 2012 15:54
Comment Bullets
<h2>What Others Are Saying...</h2>
<% @comments.each do |comment| %>
<li><%= comment.email %></li>
<li><%= comment.body %></li>
<% end %>
<hr>
<%= render "comments/comment_form" %>
@telagraphic
telagraphic / index.html.erb
Created August 16, 2012 18:19
Comment.count
<% if user_signed_in? %>
<%= link_to "New Post", new_post_path %>
<% end %>
<article class="post">
<% @posts.each do |post| %>
<h1><%= link_to post.title, post %></h1>
<h4> Posted <a href="#"><July 13, 2012><%= post.created_at.strftime("%d %b. %Y") %></a> </h4>
<h5><%= @comments.count %></h5>
@telagraphic
telagraphic / comments_controller.rb
Created September 2, 2012 16:38
Rails Comments
class CommentsController < ApplicationController
before_filter :get_post
def get_post
@post = Post.find(params[:post_id]) # comment model has this table, so why are we calling it on post db?
end
def create
@comment = @post.comments.new(params[:comment])
class Action < ActiveRecord::Base
belongs_to :day
attr_accessible :energy, :mood, :overall
end
No route matches {:action=>"show", :controller=>"habits", :day_id=>#<Day id: 4, wake: "7:30 am", sleep: "", created_at: "2012-09-09 20:11:48", updated_at: "2012-09-09 20:11:48">, :id=>nil}
Life::Application.routes.draw do
root :to => "Days#index"
resources :days do
resources :habits
end
end
@telagraphic
telagraphic / models
Created September 13, 2012 16:46
devise
class Day < ActiveRecord::Base
attr_accessible :sleep, :wake
has_one :habit, :dependent => :destroy
belongs_to :user
end
class Habit < ActiveRecord::Base
belongs_to :day
attr_accessible :energy, :mood, :overall
class FeedsController < ApplicationController
def index
@day = Day.find(params[:day_id])
@feed = @day.feeds.build # build association object
@feeds = @day.feeds.all # list all feed submits
end
def create
@day = Day.find(params[:day_id])