Skip to content

Commit

Permalink
better general styling
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed Mar 17, 2021
1 parent de5e265 commit 8e8d345
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
13 changes: 7 additions & 6 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ class PostsController < ApplicationController
before_action :set_post, only: %i[ show edit update destroy ]

def index
@posts = Post.all
# only active subscribers can see premium posts
if current_user.subscription_status == "active"
@posts = Post.all
else
@posts = Post.free
end
# if current_user.subscription_status == "active"
# @posts = Post.all
# else
# @posts = Post.free
# end
end

def show
# only active subscribers can see premium posts
if @post.premium? && current_user.subscription_status != "active"
redirect_to posts_path, alert: "#{@post.title} is available only for premium subscribers"
redirect_to posts_path, alert: "Post for premium subscribers"
end
end

Expand Down
25 changes: 16 additions & 9 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
</head>

<body>
<center>
<h1>Stripe SaaS freemium blog demo</h1>
<%= link_to "Source code", "https://github.com/yshmarov/saasblog", target: "_blank" %>
</center>
<hr>
<p class="notice" style="background-color: green;"><%= notice %></p>
<p class="alert" style="background-color: red;"><%= alert %></p>
<%= link_to "Posts", posts_path %>
<%= link_to "Pricing", pricing_path %>
<% if current_user %>
<%= link_to "BillingPortal", billing_portal_create_path, method: :post, data: { disable_with: "validating..."} %>
<% if user_signed_in? %>
<br>
<%= link_to "Posts", posts_path %>
<br>
<%= link_to "Pricing", pricing_path %>
<br>
<%= link_to "Stripe BillingPortal", billing_portal_create_path, method: :post, data: { disable_with: "validating..."} %>
<br>
<%= link_to current_user.email, edit_user_registration_path %>
<%= link_to "Log out", destroy_user_session_path, method: :delete %>
<br>
Stripe customer id:
<%= current_user.stripe_customer_id %>
Expand All @@ -29,11 +37,10 @@
<br>
Subscription status:
<%= current_user.subscription_status %>
<% else %>
<%= link_to "Log in", new_user_session_path %>
<%= link_to "Register", new_user_registration_path %>
<br>
<%= link_to "Log out", destroy_user_session_path, method: :delete %>
<hr>
<% end %>
<hr>
<%= yield %>
</body>
</html>
8 changes: 7 additions & 1 deletion app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ Premium Posts:
<tr>
<td><%= index + 1 %></td>
<td><%= post.title %></td>
<td><%= truncate(post.content, length: 17) %></td>
<td>
<% if post.premium? && current_user.subscription_status != "active" %>
<%= link_to "SUBSCRIBE TO VIEW", pricing_path %>
<% else %>
<%= truncate(post.content, length: 17) %>
<% end %>
</td>
<td><%= post.premium %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.hosts << "a85e17f9167242b59d39b7acbc4d1b0e.vfs.cloud9.eu-central-1.amazonaws.com"
config.hosts << "ad3f0369707e49e0a641afda0bd0d7ba.vfs.cloud9.eu-central-1.amazonaws.com"
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
4 changes: 3 additions & 1 deletion config/initializers/stripe.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Stripe.api_key = Rails.application.credentials[:stripe][:secret]
if Rails.application.credentials[:stripe].present? && Rails.application.credentials[:stripe][:secret].present?
Stripe.api_key = Rails.application.credentials[:stripe][:secret]
end

0 comments on commit 8e8d345

Please sign in to comment.