2017-07-16 6 views
0

私はUserモデルを持っています。ユーザーは、雇用主または学生になることができます。だから、雇用者モデルと学生モデルがあります。どちらもユーザーに属します。雇用者だけが学生プロフィールを見ることができます。したがって、プロフィールに何か問題がある場合、雇用者はプロフィールを報告できるはずです。私は、雇用者だけが見ることができるプロファイルに「レポート」ボタンがあると考えていました。彼らがそれをクリックすると、管理者(私)は学生のURLまたはIDで電子メールを受け取ります。ユーザーはどのようにして別のユーザーに報告できますか?

現在、学生プロフィールのURLはwww.mywebsite.com/students/john-bigのように見えます。 URL全体またはユーザーID(John-big)が電子メールで送信されるように、レポートボタンをどのように設定できますか。

メーラーは、ユーザーがサインアップするたびにメールが届くように設定されているので、既に設定されています。私は同じ論理を使って自分自身にメールを送ることができますが、IDやURLをつかむことが問題です。それを行う最善の方法は何ですか?

のUserInfoコントローラ(のuserinfo =学生):

class UserinfosController < ApplicationController 
    before_action :find_userinfo, only: [:show, :edit, :update, :destroy, :log_impression] 
    before_action :authenticate_user! 


    def index 
    end 

    def show 
    end 

    def new 
     @userinformation = current_user.build_userinfo 
    end 

    def create 
     @userinformation = current_user.build_userinfo(userinfo_params) 
     if @userinformation.save 
      redirect_to userinfo_path(@userinformation) 
     else 
      render 'new' 
     end 
    end 

    def edit 
    end 

    def update 
     if @userinformation.update(userinfo_params) 
      redirect_to userinfo_path(@userinformation) 
     else 
      render 'edit' 
     end 
    end 

    def destroy 
     @userinformation.destroy 
     redirect_to root_path 
    end 


    private 
     def userinfo_params 
      params.require(:userinfo).permit(:name, :email, :college, :gpa, :major) 
     end 

     def find_userinfo 
      @userinformation = Userinfo.friendly.find(params[:id]) 
     end 
end 

雇用コントローラ:

class EmployersController < ApplicationController 
    before_action :find_employer, only: [:show, :edit, :update, :destroy] 

    def index 
    end 

    def show 
    end 

    def new 
     @employer = current_user.build_employer 
    end 

    def create 
     @employer = current_user.build_employer(employer_params) 
     if @employer.save 
      redirect_to userinfos_path 
     else 
      render 'new' 
     end 
    end 

    def edit 
    end 

    def update 
     if @employer.update(employer_params) 
      redirect_to employer_path(@employer) 
     else 
      render 'edit' 
     end 
    end 

    def destroy 
     @employer.destroy 
     redirect_to root_path 
    end 

    private 
     def employer_params   
      params.require(:employer).permit(:paid, :name, :company, :position, :number, :email, :emp_img) 
     end 

     def find_employer 
      @employer = Employer.friendly.find(params[:id]) 
     end 
end 

Userモデル:

class User < ActiveRecord::Base 
    has_one :userinfo 
    has_one :employer 

    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    acts_as_messageable 

    after_create :welcome_send 

    def welcome_send 
    WelcomeMailer.welcome_send(self).deliver_now 
    end 

end 

君たち場合は私に知らせてくださいねd詳細をご覧ください。

+0

あなたは 'user_info_url(@user_info)'を使うことができます。あるいは単にメーラービューの中にidを表示することもできます。 –

答えて

0

ビューのURL(学生プロフィールのURL)を取得するにはrequest.url()を使用します。

<%= debug("request.url: #{request.url()}") if Rails.env.development? %> 

私はこのことができます願っています:あなたにこれを追加すること

てみての感覚を得るために表示します。

+0

ありがとう、それは動作します。それを私に送る最善の方法は何だと思いますか? 「レポート」というボタンを作成できますか?誰かがそれをクリックすると、私にURLをメールしますか?これは可能ですか? – LizzyTheLearner

+0

ようこそ。 Railsで電子メールを送信すること自体、全体的な課題です。メーラーを設定する必要があります。とにかく、私のクイックテイクは次のようなものです。関連するビューに、そのレポートボタン、form_buttonなどのフォームを作成します。ボタンをクリックすると、form_buttonフォームは関連するコントローラのレポートアクションにルーティングされます。そのコントローラーアクションから、電子メールを生成します。 –

+0

よろしいですか?私はすでにメーラーをセットアップしています。今、ユーザーがサインアップすると、私は自分のadmin-emailに電子メールを送ります。そのコードを含めるように質問を更新します。それは似ているだろうか? – LizzyTheLearner

関連する問題