Skip to content

Instantly share code, notes, and snippets.

<ul class='attributes'>
<% @forums.each do |forum| %>
<%= link_to forum.title, forum_path(forum), class: 'btn btn-primary' %>
<% end %>
</ul>
class AddTopicsToForums < ActiveRecord::Migration
def change
add_column :forum, :topics, index: true, foreign_key: true
end
end
<li><%= link_to "Delete", [@forum, @topic], method: :destroy,
data: { confirm: "Are you sure you want to delete this topic?" }, class: "delete" %></li>
require 'rails_helper'
RSpec.describe "Users can edit topics" do
let(:author) { FactoryGirl.create(:user) }
let(:forum) { FactoryGirl.create(:forum) }
let(:topic) { FactoryGirl.create(:topic, forum: forum, author: author) }
before do
login_as(author)
visit forum_topic_path(forum, topic)
module ApplicationHelper
def admins_only(&block)
block.call if current_user.try(:admin?)
end
def author_only(&block)
block.call if current_user == @topic.author.email
end
end
module ApplicationHelper
require 'pry'
def admins_only(&block)
block.call if current_user.try(:admin?)
end
def author_only(&block)
binding.pry
block.call if current_user == @topic.author.email
<div class='page-header'>
<h1>Welcome to the Forums!</h1>
</div>
<h2>Announcements</h2>
<p>
May 12th, 2016 - The infamous hacker known as Radar has once again infiltrated the website!<br>
Please notify the mods of any suspicous behavior.
</p>
# The test that is failing
require 'rails_helper'
RSpec.describe "Users can leave comments" do
let(:user) { FactoryGirl.create(:user) }
let(:topic) { FactoryGirl.create(:topic, author: user, forum: forum) }
let(:forum) { FactoryGirl.create(:forum) }
before do
class AddAuthorToComments < ActiveRecord::Migration
def change
add_reference :comments, :author, index: true
add_foreign_key :comments, :users, column: :author_id
end
end
class Comment < ActiveRecord::Base
belongs_to :topic
belongs_to :author, class_name: "User"
validates :text, presence: true, length: { minimum: 15 }
end