Skip to content

Instantly share code, notes, and snippets.

@kareemgrant
Last active August 29, 2015 14:16
Show Gist options
  • Save kareemgrant/c5bc607ebd9da83b6d27 to your computer and use it in GitHub Desktop.
Save kareemgrant/c5bc607ebd9da83b6d27 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Railsapp4</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= flash[:notice] if flash[:notice] %>
<%= flash[:alert] if flash[:alert] %>
<%= yield %>
</body>
</html>
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def current_user
@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
end
helper_method :current_user
end
<% if current_user %>
<%= link_to 'LOG OUT', loggedout_path %>
<% else %>
<%= link_to 'SIGN UP', new_user_path %>
<%= link_to 'LOGIN', login_path %>
<% end %>
<h1>Posts</h1>
<body>
<% @posts.each do |post| %>
<h3><%= link_to post.headline, post_path(post) %></h3>
<p><%= post.body %></p>
<% end %>
<br>
<b><%= link_to 'CREATE A NEW POST', new_post_path %></b>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment