diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/blog-app.iml b/.idea/blog-app.iml new file mode 100644 index 0000000..5fc63fb --- /dev/null +++ b/.idea/blog-app.iml @@ -0,0 +1,582 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codestyles/codeStyleConfig.xml b/.idea/codestyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codestyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..f35f58b --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,32 @@ + + + + + postgresql + true + true + $PROJECT_DIR$/config/database.yml + org.postgresql.Driver + jdbc:postgresql://127.0.0.1:5432/blog_app_development + $ProjectFileDir$ + + + postgresql + true + true + $PROJECT_DIR$/config/database.yml + org.postgresql.Driver + jdbc:postgresql://127.0.0.1:5432/blog_app_test + $ProjectFileDir$ + + + postgresql + true + true + $PROJECT_DIR$/config/database.yml + org.postgresql.Driver + jdbc:postgresql://127.0.0.1:5432/blog_app_production + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..cff1354 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..fe02277 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4abf1dc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Gemfile b/Gemfile index 53f4c52..4abfcdf 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 7.0.3' gem 'sprockets-rails' # Use postgresql as the database for Active Record -gem 'pg' +gem 'pg', '~> 1.1' # Use the Puma web server [https://github.com/puma/puma] gem 'puma', '~> 5.0' @@ -51,7 +51,6 @@ gem 'bootsnap', require: false # gem "image_processing", "~> 1.2" gem 'ffi' - group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem 'rails-controller-testing' @@ -60,6 +59,7 @@ end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] + gem 'bullet' gem 'web-console' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] @@ -75,3 +75,5 @@ group :test do gem 'selenium-webdriver' gem 'webdrivers' end + +gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 0f7d4aa..d25e05c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,10 +69,14 @@ GEM addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) + bcrypt (3.1.18) bindex (0.8.1) - bootsnap (1.13.0) + bootsnap (1.12.0) msgpack (~> 1.2) builder (3.2.4) + bullet (7.0.2) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.11) capybara (3.37.1) addressable matrix @@ -85,15 +89,22 @@ GEM childprocess (4.1.0) concurrent-ruby (1.1.10) crass (1.0.6) + devise (4.8.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) diff-lcs (1.5.0) digest (3.1.0) erubi (1.10.0) ffi (1.15.5) + ffi (1.15.5-x64-mingw-ucrt) globalid (1.0.0) activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - importmap-rails (1.1.5) + importmap-rails (1.1.3) actionpack (>= 6.0.0) railties (>= 6.0.0) jbuilder (2.11.5) @@ -110,7 +121,7 @@ GEM method_source (1.0.0) mini_mime (1.1.2) minitest (5.16.2) - msgpack (1.5.4) + msgpack (1.5.3) net-imap (0.2.3) digest net-protocol @@ -126,12 +137,18 @@ GEM net-protocol timeout nio4r (2.5.8) - nokogiri (1.13.8-x86_64-linux) + nokogiri (1.13.7-arm64-darwin) racc (~> 1.4) + nokogiri (1.13.7-x64-mingw-ucrt) + racc (~> 1.4) + nokogiri (1.13.7-x86_64-linux) + racc (~> 1.4) + orm_adapter (0.5.0) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) - pg (1.4.2) + pg (1.4.1) + pg (1.4.1-x64-mingw-ucrt) public_suffix (4.0.7) puma (5.6.4) nio4r (~> 2.0) @@ -172,6 +189,9 @@ GEM rainbow (3.1.1) rake (13.0.6) regexp_parser (2.5.0) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) rexml (3.2.5) rspec-core (3.11.0) rspec-support (~> 3.11.0) @@ -190,14 +210,14 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (1.32.0) + rubocop (1.31.2) json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.19.1, < 2.0) + rubocop-ast (>= 1.18.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.19.1) @@ -216,20 +236,23 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - stimulus-rails (1.1.0) + stimulus-rails (1.0.4) railties (>= 6.0.0) - strscan (3.0.4) + strscan (3.0.3) thor (1.2.1) timeout (0.3.0) turbo-rails (1.1.1) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) - tzinfo (2.0.5) + tzinfo (2.0.4) concurrent-ruby (~> 1.0) tzinfo-data (1.2022.1) tzinfo (>= 1.0.0) unicode-display_width (2.2.0) + uniform_notifier (1.16.0) + warden (1.2.9) + rack (>= 2.0.9) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -248,15 +271,19 @@ GEM zeitwerk (2.6.0) PLATFORMS + arm64-darwin-21 + x64-mingw-ucrt x86_64-linux DEPENDENCIES bootsnap + bullet capybara + devise ffi importmap-rails jbuilder - pg + pg (~> 1.1) puma (~> 5.0) rails (~> 7.0.3) rails-controller-testing diff --git a/README.md b/README.md index 79766e4..0f0bcb1 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,12 @@ This project is build with: - Twitter: [@Evans_22J](https://twitter.com/Evans_22J) - LinkedIn: [@Evans Sitibekiso](https://www.linkedin.com/in/evans-sitibekiso/) +👤 **Edward Odhiambo** + +- GitHub: [@whit3d](https://github.com/white3d) +- Twitter: [@odhiambo_ed](https://twitter.com/odhiambo_ed) +- LinkedIn: [Edward Odhiambo](https://www.linkedin.com/in/edward-odhiambo-6a462a21b/) + ## 🤝 Contributor @@ -192,4 +198,4 @@ Give a ⭐️ if you like this project! ## 📝 License -This project is [MIT](./MIT.md) licensed. +This project is [MIT](https://github.com/microverseinc/readme-template/blob/master/MIT.md) licensed. diff --git a/app/assets/images/margaret.jpeg b/app/assets/images/margaret.jpeg new file mode 100644 index 0000000..afae880 Binary files /dev/null and b/app/assets/images/margaret.jpeg differ diff --git a/app/assets/stylesheets/user_style.css b/app/assets/stylesheets/user_style.css index 79e0f7a..6404f68 100644 --- a/app/assets/stylesheets/user_style.css +++ b/app/assets/stylesheets/user_style.css @@ -150,7 +150,9 @@ a { } .button-user { - text-align: center; + display: flex; + justify-content: center; + align-items: center; } .text-button { @@ -162,14 +164,15 @@ a { background-color: #2f4858; border: none; color: white; - padding: 10px 20px; + padding: 15px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; - margin: 4px 2px; + margin: 10px; cursor: pointer; border-radius: 4px; + width: 150px; } .post-info, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 76d31c2..f1c48b6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,11 @@ class ApplicationController < ActionController::Base - def current_user - User.first + before_action :authenticate_user! + protect_from_forgery with: :exception + before_action :update_allowed_parameters, if: :devise_controller? + + def update_allowed_parameters + devise_parameter_sanitizer.permit(:sign_up) do |field| + field.permit(:name, :photo, :bio, :posts_counter, :email, :password, :password_confirmation) + end end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..4dbb215 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,29 @@ +class CommentsController < ApplicationController + def new + @comment = Comment.new + @user = current_user + end + + def create + @post = Post.find(params[:post_id] || params[:id]) + @comment = Comment.new(comment_params) + @comment.author_id = current_user.id + @comment.post = @post + + respond_to do |format| + if @comment.save! + format.html do + redirect_to user_post_url(current_user, @post), notice: 'Comment was successfully created.' + end + else + format.html { render :new, status: :unprocessable_entity } + end + end + end + + private + + def comment_params + params.require(:comment).permit(:text) + end +end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb new file mode 100644 index 0000000..39a16b2 --- /dev/null +++ b/app/controllers/likes_controller.rb @@ -0,0 +1,20 @@ +class LikesController < ApplicationController + def new + @like = Like.new + @user = current_user + end + + def create + @post = Post.find(params[:post_id] || params[:id]) + @like = Like.new(post_id: @post.id, author_id: current_user.id) + @like.author_id = current_user.id + + respond_to do |format| + if @like.save + format.html { redirect_to user_post_url(current_user, @post), notice: 'Like was successfully created.' } + else + format.html { render :new, status: :unprocessable_entity } + end + end + end +end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 722bbd0..9a093ef 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,10 +1,40 @@ class PostsController < ApplicationController + before_action :set_post, only: %i[show edit update destroy] + def index - @user = User.find(params[:user_id]) - @posts = @user.posts + @user = current_user + @posts = @user.posts.includes(:comments) end def show @post = Post.find(params[:id]) end + + def new + @post = Post.new + @user = current_user + end + + def create + @post = Post.new(post_params) + @post.author_id = current_user.id + + respond_to do |format| + if @post.save + format.html { redirect_to user_post_url(current_user, @post), notice: 'Post was successfully created.' } + else + format.html { render :new, status: :unprocessable_entity } + end + end + end + + private + + def set_post + @post = Post.find(params[:id]) + end + + def post_params + params.require(:post).permit(:title, :text, :comments_counter, :likes_counter) + end end diff --git a/app/models/post.rb b/app/models/post.rb index 21254b2..d03e3bd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,8 +4,8 @@ class Post < ApplicationRecord validates :likes_counter, numericality: { only_integer: true, greater_than_or_equal_to: 0 } belongs_to :author, class_name: 'User' - has_many :comments, class_name: 'Comment', foreign_key: 'post_id' - has_many :likes, class_name: 'Like', foreign_key: 'post_id' + has_many :comments, foreign_key: 'post_id' + has_many :likes, foreign_key: 'post_id' after_save :update_posts_counter diff --git a/app/models/user.rb b/app/models/user.rb index 4d30401..ba380cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,12 +1,25 @@ class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable + validates :name, presence: true, allow_blank: false validates :posts_counter, numericality: { only_integer: true, greater_than_or_equal_to: 0 } has_many :posts, foreign_key: 'author_id' has_many :comments, foreign_key: 'author_id' - has_many :likes, class_name: 'like', foreign_key: 'author_id' + has_many :likes, foreign_key: 'author_id' + + after_initialize :set_defaults def recent_posts posts.order(created_at: :desc).limit(3) end + + private + + def set_defaults + self.posts_counter ||= 0 + end end diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb new file mode 100644 index 0000000..c8635e0 --- /dev/null +++ b/app/views/comments/new.html.erb @@ -0,0 +1,14 @@ +
+

Add New Comment :

+ <%= form_with model: @comment, url: user_post_comments_path, method: :post, local: true, class: "form-control" do |form| %> + +
+ <%= form.label :text %> + <%= form.text_area :text, placeholder: "Type your comment here!", rows: 20, required: true, class: "form-post-text" %> +
+ +
+ <%= form.submit "Save", class: "button" %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 0000000..b12dd0c --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..dc55f64 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb new file mode 100644 index 0000000..32f4ba8 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 0000000..b41daf4 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..f667dc1 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..41e148b --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000..5fbb9ff --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 0000000..9b486b8 --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,16 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Send me reset password instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 0000000..38d95b8 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,43 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
+ <%= @minimum_password_length %> characters minimum + <% end %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "current-password" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000..d655b66 --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 0000000..5ede964 --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,26 @@ +

Log in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "current-password" %> +
+ + <% if devise_mapping.rememberable? %> +
+ <%= f.check_box :remember_me %> + <%= f.label :remember_me %> +
+ <% end %> + +
+ <%= f.submit "Log in" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/shared/_error_messages.html.erb b/app/views/devise/shared/_error_messages.html.erb new file mode 100644 index 0000000..ba7ab88 --- /dev/null +++ b/app/views/devise/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if resource.errors.any? %> +
+

+ <%= I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %> +

+ +
+<% end %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb new file mode 100644 index 0000000..96a9412 --- /dev/null +++ b/app/views/devise/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), method: :post %>
+ <% end %> +<% end %> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 0000000..ffc34de --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6cdc32f..f3979f9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,27 +1,29 @@ - - BlogApp - - <%= csrf_meta_tags %> - <%= csp_meta_tag %> + + BlogApp + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> - - <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> - + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + - - <%= yield %> + +
<%= notice %>
+
<%= alert %>
+<%= yield %> - - + + \ No newline at end of file diff --git a/app/views/likes/new.html.erb b/app/views/likes/new.html.erb new file mode 100644 index 0000000..7649c46 --- /dev/null +++ b/app/views/likes/new.html.erb @@ -0,0 +1,5 @@ +
+ <%= form_with(model: @like, url: user_post_likes_path) do |form| %> + <%= form.submit 'Add Like', class: "button" %> + <% end %> +
\ No newline at end of file diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 60fdccc..1107702 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -33,6 +33,7 @@ <% end %>
+ <%= button_to 'Add New Post', new_user_post_url(id: @user.id), method: :get, class: "button"%> diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb new file mode 100644 index 0000000..0bb4a1b --- /dev/null +++ b/app/views/posts/new.html.erb @@ -0,0 +1,23 @@ + + +
+

Add New Post :

+ <%= form_with model: @post, url: user_posts_path, method: :post, local: true, class: "form-control" do |form| %> + <%= form.hidden_field :comments_counter, value: 0 %> + <%= form.hidden_field :likes_counter, value: 0 %> + +
+ <%= form.label :title %> + <%= form.text_field :title, placeholder: "Title", required: true, class: "form-post-title" %> +
+ +
+ <%= form.label :text %> + <%= form.text_area :text, placeholder: "Type your post here!", rows: 20, required: true, class: "form-post-text" %> +
+ +
+ <%= form.submit "Save", class: "button" %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 077f30a..f8dd84e 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -19,5 +19,14 @@

<% end %> - + +
+ <%= button_to "Back", user_path(@post.author, @post), method: :get, class: "button" %> + <%= button_to "Add Comment", new_user_post_comment_path(@post.author, @post), method: :get, class: "button" %> +
+ <%= form_with model: @like, url: "/users/#{params['user_id']}/posts/#{params['id']}/likes", method: :post , local: true do |form|%> + <%= form.submit "Like", class: 'button' %> + <% end %> +
+
\ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 84f1b7d..ac5d553 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,12 +1,12 @@
<% @users.each do |user| %> -
+
alt="user"> - <% end %> -
+ \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index a85f0e0..52f87f1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,4 +1,4 @@ -
+
alt="user"/>