class WebLoginsController < ApplicationController
before_action :set_web_login, only: [:show, :edit, :update, :destroy]
# GET /web_logins
# GET /web_logins.json
def index
@web_logins = WebLogin.order(:name)
end
# GET /web_logins/1
# GET /web_logins/1.json
def show
end
# GET /web_logins/new
def new
@web_login = WebLogin.new
end
# GET /web_logins/1/edit
def edit
end
# POST /web_logins
# POST /web_logins.json
def create
@web_login = WebLogin.new(web_login_params)
respond_to do |format|
if @web_login.save
format.html { redirect_to @web_login, notice: 'Web login was successfully created.' }
format.json { render :show, status: :created, location: @web_login }
else
format.html { render :new }
format.json { render json: @web_login.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /web_logins/1
# PATCH/PUT /web_logins/1.json
def update
respond_to do |format|
if @web_login.update(web_login_params)
format.html { redirect_to @web_login, notice: 'Web login was successfully updated.' }
format.json { render :show, status: :ok, location: @web_login }
else
format.html { render :edit }
format.json { render json: @web_login.errors, status: :unprocessable_entity }
end
end
end
# DELETE /web_logins/1
# DELETE /web_logins/1.json
def destroy
@student = Student.where(["web_logins_id = ?", @web_login.id])
@web_login.destroy
@student.each do |stu_web|
stu_web.destroy
end
respond_to do |format|
format.html { redirect_to web_logins_url, notice: 'Web login was successfully deleted.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_web_login
@web_login = WebLogin.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def web_login_params
params.require(:web_login).permit(:name, :password)
end
def encrypt_pass
salt = BCrypt::Engine.generate_salt
encypted = BCrypt::Engine.hash_secret(:password, salt)
end
end
<%= pluralize(@web_login.errors.count, "error") %> prohibited this web_login from being saved:
Editing Web Login
Users Create Login Here
Name
Encrypted Password
Links
<%= web_login.name %>
<%= web_login.password_digest %>
<%= link_to 'Show', web_login %>
<%= link_to 'Edit', edit_web_login_path(web_login) %>
<%= link_to 'Delete', web_login, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to 'Add Student', new_web_login_student_path(web_login) %>
New Web Login
class CreateWebLogins < ActiveRecord::Migration
#belongs_to :students
def change
change_table :web_logins do |t|
t.string :name
t.string :password
t.timestamps null: false
end
end
end
No comments:
Post a Comment
Thank you very much for viewing this entry and I hope you are able to return soon to continue to enjoy more of the site.
Please share your thoughts in the comment section.
Be blessed and enjoy life!
Note: Only a member of this blog may post a comment.