0
我有一個應用程序,其中: 1.用戶在頁面上查看他們的個人資料信息 2.用戶按下按鈕,通過此頁面 3.電子郵件後發送電子郵件的人發送,用戶發送回到查看他們的個人資料信息,並通知閃爍,告訴他們電子郵件是否工作。無法重定向到零! ActionController的:: ActionControllerError
我有沒有。 3.我不知道如何設置一個重定向(或別的情況而定),將發送用戶查看他們的個人資料信息再次
控制器:
class ProfilesController < ApplicationController
before_action :set_profile, only: [:show, :edit, :update, :destroy, :email]
# GET /profiles
# GET /profiles.json
def index
@profiles = Profile.all
end
# GET /profiles/1
# GET /profiles/1.json
def show
end
# GET /profiles/new
def new
@profile = Profile.new
end
# GET /profiles/1/edit
def edit
@profile = Profile.find_by user_id: current_user.id
end
# POST /profiles
# POST /profiles.json
def create
@profile = Profile.new(profile_params)
respond_to do |format|
if @profile.save
format.html { redirect_to @profile, notice: 'Profile was successfully created.' }
format.json { render :show, status: :created, location: @profile }
else
format.html { render :new }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /profiles/1
# PATCH/PUT /profiles/1.json
def update
respond_to do |format|
if @profile.update(profile_params)
format.html { redirect_to @profile, notice: 'Profile was successfully updated.' }
format.json { render :show, status: :ok, location: @profile }
else
format.html { render :edit }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
# DELETE /profiles/1
# DELETE /profiles/1.json
def destroy
@profile.destroy
respond_to do |format|
format.html { redirect_to profiles_url, notice: 'Profile was successfully destroyed.' }
format.json { head :no_content }
end
end
def email_profile
destination = params[:to]
share = Share.profile(@profile, destination)
if destination =~ /@/ && share.deliver
redirect_to @profile, notice: 'email sent'
else
redirect_to @profile, notice: 'email failed'
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_profile
@profile = Profile.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def profile_params
params.require(:profile).permit(:user_id, :first_name, :last_name, :dob, :email, :mobile, :address, :suburb, :postcode, :city, :state, :country)
end
end
分享梅勒:
class Share < ActionMailer::Base
default_url_options[:host] = "localhost:3000"
default from: "[email protected]"
def profile(profile, destination)
@profile = profile
mail(to: destination, subject: "sent you stuff")
end
end
當前出錯:
ActionController::ActionControllerError in ProfilesController#email_profile
Cannot redirect to nil!
我覺得它有什麼做的:不爲是p id參數稱職通過發送電子郵件後..但我是一個新手,所以我真的不知道我在說什麼..感謝任何指導,所以我可以解決這個問題,也更好地瞭解ROR :)
你的'@ profile'實例變量是'nil'。顯示你所有的控制器。 – 2014-08-28 09:02:11
如果可能,請使用「Share」模式! – 2014-08-28 09:12:14
你可能需要先找到一個'@ profile'。也許像'Profile.find(params [:profile_id])缺失.'但我同意@Marek Lipka請包括控制器代碼。 – wpp 2014-08-28 10:07:51