好吧,我對鐵軌相當陌生。我已成功創建了一個存儲登錄信息的rails應用程序。我使用devise進行用戶管理並安裝了cancan,但不知道如何使用它。如何僅在Ruby on Rails中向登錄用戶顯示帖子?
不管怎麼說,
現在,如果您登錄與否沒有關係,該網站顯示你已經被任何用戶輸入的所有的「後」或「主菜」。我需要一種方法來限制這種只顯示後由當前登錄的用戶中所做的
我已經通過研究,我需要在這裏做一些發現:
class FtpLoginsController < ApplicationController
before_action :set_ftp_login, only: [:show, :edit, :update, :destroy]
# GET /ftp_logins
# GET /ftp_logins.json
def index
@ftp_logins = FtpLogin.all
end
# GET /ftp_logins/1
# GET /ftp_logins/1.json
def show
end
# GET /ftp_logins/new
def new
@ftp_login = FtpLogin.new
end
# GET /ftp_logins/1/edit
def edit
end
# POST /ftp_logins
# POST /ftp_logins.json
def create
@ftp_login = FtpLogin.new(ftp_login_params)
respond_to do |format|
if @ftp_login.save
format.html { redirect_to @ftp_login, notice: 'Ftp login was successfully created.' }
format.json { render action: 'show', status: :created, location: @ftp_login }
else
format.html { render action: 'new' }
format.json { render json: @ftp_login.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /ftp_logins/1
# PATCH/PUT /ftp_logins/1.json
def update
respond_to do |format|
if @ftp_login.update(ftp_login_params)
format.html { redirect_to @ftp_login, notice: 'Ftp login was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @ftp_login.errors, status: :unprocessable_entity }
end
end
end
# DELETE /ftp_logins/1
# DELETE /ftp_logins/1.json
def destroy
@ftp_login.destroy
respond_to do |format|
format.html { redirect_to ftp_logins_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_ftp_login
@ftp_login = FtpLogin.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def ftp_login_params
params.require(:ftp_login).permit(:client_name, :website_name, :ftp_login, :ftp_password, :notes)
end
end
如果有人能討好在這裏給我正確的方向,這將是太棒了!
在此先感謝。
好吧,這是我.. 類FtpLoginsController
jhammond2012
你可以粘貼你在FtpLogin和用戶模型之間建立的關係嗎 –
有沒有辦法直接與你聯繫? – jhammond2012