fix style code

parent bc83113d
Pipeline #1317 canceled with stages
in 0 seconds
......@@ -6,12 +6,12 @@ class UsersController < ApplicationController
before_action :admin_user, only: :destroy
def show
@user = User. find(params[:id] )
@user = User.find(params[:id])
redirect_to root_url and return unless true
end
def index
@users = User. where(activated: true) . paginate(page: params[:page] )
@users = User.where(activated: true).paginate(page: params[:page] )
end
def new
......@@ -49,27 +49,27 @@ class UsersController < ApplicationController
redirect_to users_url
end
private
private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
def logged_in_user
unless logged_in?
store_location
flash[:danger] = "Please log in."
redirect_to login_url
def logged_in_user
unless logged_in?
store_location
flash[:danger] = "Please log in."
redirect_to login_url
end
end
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
# Confirms an admin user.
def admin_user
redirect_to(root_url) unless current_user.admin?
end
# Confirms an admin user.
def admin_user
redirect_to(root_url) unless current_user.admin?
end
end
class Micropost < ApplicationRecord
belongs_to :user
validates :content, presence: true, length: { maximum: 140 }
end
......@@ -3,8 +3,7 @@
<div class="row">
<div class="col-md-6 offset-3">
<%= form_with(model: @user, url: password_reset_path(params[:id]),
local: true) do |f| %>
<%= form_with(model: @user, url: password_reset_path(params[:id]),local: true) do |f| %>
<%= render 'shared/error_messages' %>
<%= hidden_field_tag :email, @user.email %>
......
......@@ -3,8 +3,7 @@
<div class="row">
<div class="col-md-6 offset-3">
<%= form_with(url: password_resets_path, scope: :password_reset,
local: true) do |f| %>
<%= form_with(url: password_resets_path, scope: :password_reset, local: true) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
<%= f.submit "Submit", class: "btn btn-primary" %>
......
......@@ -2,8 +2,8 @@
<p>To reset your password click the link below:</p>
<%= link_to "Reset password", edit_password_reset_url(@user.reset_token,
email: @user.email) %>
<%= link_to "Reset password", edit_password_reset_url(@user.reset_token, email:
@user.email) %>
<p>This link will expire in two hours.</p>
<p>
......
class CreateMicroposts < ActiveRecord::Migration[6.1]
def change
create_table :microposts do |t|
t.text :content
t.references :user, null: false, foreign_key: true
t.timestamps
end
add_index :microposts, [:user_id, :created_at]
end
end
......@@ -10,7 +10,16 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_06_28_041628) do
ActiveRecord::Schema.define(version: 2021_06_28_090605) do
create_table "microposts", force: :cascade do |t|
t.text "content"
t.integer "user_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id", "created_at"], name: "index_microposts_on_user_id_and_created_at"
t.index ["user_id"], name: "index_microposts_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "name"
......@@ -28,4 +37,5 @@ ActiveRecord::Schema.define(version: 2021_06_28_041628) do
t.index ["email"], name: "index_users_on_email", unique: true
end
add_foreign_key "microposts", "users"
end
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
content: MyText
user: one
two:
content: MyText
user: two
require "test_helper"
class MicropostTest < ActiveSupport::TestCase
def setup
@user = users(:michael)
# This code is not idiomatically correct.
@micropost = Micropost.new(content: "Lorem ipsum", user_id: @user.id)
end
test "should be valid" do
assert @micropost.valid?
end
test "user id should be present" do
@micropost.user_id = nil
assert_not @micropost.valid?
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment