2014-04-11 3 views
1

devise가없는 부모 모델과 devise가없는 자식 모델이있는 중첩 된 폼이 있습니다. 사용자 모델 필드가 있고 내부에 전문가 모델 필드가 중첩 된 편집 양식을 작성 중입니다. 업데이트 저장은 작동하지만 로그 아웃되고 "계속하기 전에 로그인 또는 가입해야합니다."라는 오류 메시지가 나타납니다. 다시 로그인하면 필드가 올바르게 업데이트 된 것을 볼 수 있습니다. 나에게 서명을하지 않고 양식을 제출할 때 업데이트 된 편집 페이지를 보여주고 싶습니다.레일 4 devise가있는 중첩 된 폼은 업데이트시에 로그 아웃합니다.

사용자 모델 - 기기가 내장되어 있습니다.

class User < ActiveRecord::Base 
// some stuff 
has_one :expert 
accepts_nested_attributes_for :expert, :update_only => true 
// more stuff 

전문가가 작성한 모델입니다.

class Expert < ActiveRecord::Base 
belongs_to :user 

사용자 컨트롤러 :

before_action :set_user, only: [:show, :edit, :update, :destroy] 
before_filter :authenticate_user!, :only => [:show, :edit] 

def edit 
    @user = User.friendly.find(params[:id]) 
    @title = "Edit Profile" 
end 

def update 
    respond_to do |format| 
    if @user.update(user_params) 
     format.html { redirect_to @user, notice: 'User was successfully updated.' } 
     format.json { head :no_content } 
    else 
     format.html { render action: 'edit' } 
     format.json { render json: @user.errors, status: :unprocessable_entity } 
    end 
    end 
end 

    private 
# Use callbacks to share common setup or constraints between actions. 
def set_user 
    @user = User.friendly.find(params[:id]) 
end 

# Never trust parameters from the scary internet, only allow the white list through. 
def user_params 
    params.require(:user).permit(:id, :name, :email, :phone, :password, :role, :expert_attributes => [:id, :Location]) 
end 

end 

전문가 컨트롤러 : 부분

def edit 
    @expert = Expert.find(params[:id]) 
    @title = "Edit Expert Profile" 
end 

사용자 편집보기 양식 : 당신의 UsersController에서

<%= form_for(@user) do |f| %> 
    <% if @user.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> 

     <ul> 
     <% @user.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :Name %><br> 
    <%= f.text_field :name, :class => "form-control" %> 
    </div> 


    <div class="field"> 
    <%= f.label :Email %><br> 
    <%= f.text_field :email, :class => "form-control" %> 
    </div> 

    <div class="field"> 
    <%= f.label :Phone %><br> 
    <%= f.text_field :phone, :class => "form-control" %> 
    </div> 


    <div class="field"> 
    <%= f.label :Password %><br> 
    <%= f.text_field :password, :class => "form-control" %> 
    </div> 

    <div class="field"> 
    <%= f.fields_for :expert do |e| %> 
     <%= e.label :Location %><br /> 
     <%= e.text_field :Location %> 
    <% end %> 
    </div> 

    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

답변

0

, 당신은 :update를 추가해야 authenticate_user! 필터로 :

+0

그래도 문제는 계속 발생합니다. – samikb