Rails에서 Devise 사용자가있는 프로필 모델

알렉스 하일

위치, 전기, blah, blah, blah와 같은 항목으로 Devise Users를위한 별도의 프로필 모델을 만들려고합니다. 문제는 데이터베이스에 저장할 수 없다는 것입니다.

내 사용자를 "아티스트"라고합니다.

### /routes.rb ###

get 'artists/:id/new_profile' => 'artists/profiles#new', as: :profile
post 'artists/:id/new_profile' => 'artists/profiles#create'

### artists/profiles_controller.rb ###

class Artists::ProfilesController < ApplicationController

  before_action :authenticate_artist!

  def new
    @artist = current_artist
    @profile = ArtistProfile.new
  end

  def create
    @artist = current_artist
    @profile = ArtistProfile.new(profile_params)
    if @profile.save
      redirect_to current_artist
    else
      render 'new'
    end
  end
end

### /artist.rb ###

class Artist < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable, :timeoutable
  has_one :artist_profile, dependent: :destroy

### /artist_profile.rb ###

class ArtistProfile < ActiveRecord::Base
  belongs_to :artist
  validates :artist_id, presence: true
end

### /views/artists/profiles/new.html.erb ###

<%= form_for(@profile, url: profile_path) do |f| %>
  <div class="field">
    <%= f.label :biography, "biography", class: "label" %>
    <%= f.text_area :biography, autofocus: true , class: "text-field" %>
  </div>
  <div class="field">
    <%= f.label :location, "location", class: "label" %>
    <%= f.text_field :location, class: "text-field" %>
  </div>
  ...
  ...
  ...
  <div class="actions">
    <%= f.submit "create profile", class: "submit-button" %>
  </div>
<% end %>

내가 여기서 뭘 잘못하고 있니?

베니토 세르나

current_artist개체를 사용하여 프로필을 초기화해야 합니다.

class Artists::ProfilesController < ApplicationController
  before_action :authenticate_artist!

  def new
    @artist = current_artist
    @profile = @artist.build_profile
  end

  def create
    @artist = current_artist
    @profile = @artist.build_profile(profile_params)
    if @profile.save
      redirect_to current_artist
    else
      render 'new'
    end
  end
end

최신 정보:

이 예를 사용하려면 협회가

class Artist < ActiveRecord::Base
  has_one :profile, class_name: ArtistProfile
end

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

두 사용자 모델 (Devise, CanCan)에 대해 Rails alias_method에서 current_user로

분류에서Dev

Rails / Devise-프로필 빌드에 사용자 이름 전달

분류에서Dev

강력한 매개 변수를 사용하여 Rails 4의 Devise 사용자 모델에 사용자 정의 필드를 추가 할 수 없습니다.

분류에서Dev

사용자 필드가있는 모델에 Django 저장

분류에서Dev

Devise + 관련 프로필 모델-오류를 반환하는 프로필 페이지 표시

분류에서Dev

Devise / Rails를 사용하여 모델에 UserID 전달

분류에서Dev

표시 : Devise in rails 앱을 사용하여 프로필 양식의 가입 양식에있는 이름

분류에서Dev

사용자 모델에 프로필을 생성하고 포함하는 방법 (사용자 모델 설계)?

분류에서Dev

Devise로 생성 된 모델에 데이터 추가를 저장할 수 없습니다 (모델명 : user).

분류에서Dev

devise 모델에 더 많은 필드를 추가하고이를 위해 form_for 사용

분류에서Dev

Rails-Devise : 사용자가 로그인 할 수 있는지 확인

분류에서Dev

Rails 4 has_many : through association : 다른 부모 모델에서 Devise current_user 사용 after_create 콜백

분류에서Dev

Rails : Devise에서 사용자를 자동으로 기억할 수 있습니까?

분류에서Dev

사용자 프로필 모델 쿼리

분류에서Dev

devise는 여러 모델에서 어떻게 작동합니까?

분류에서Dev

Rails, Devise 다중 모델 로그인 및 세션

분류에서Dev

Rails, Devise 다중 모델 로그인 및 세션

분류에서Dev

사용자 모델에서 액세스 할 수있는 '사용자 이름'속성을 만들 수 없음 (레일 4-Devise)

분류에서Dev

Devise Rails에서 로그인시 직접 사용자

분류에서Dev

Devise로 내 사용자 모델에 외부 관계를 추가 한 다음 업데이트하려고합니다.

분류에서Dev

Rails Devise는 로그인시 사용자를 추가합니다.

분류에서Dev

Flask : 모델을 파일에 연결 (예 : 프로필 사진)

분류에서Dev

Rails, Devise-관리자가 다른 사용자 프로필을 편집하려고합니다. 대신 자신의 프로필이로드되었습니다.

분류에서Dev

Rails-Devise-별도의 테이블에 프로필 정보 추가

분류에서Dev

필드가있는 Rails ElasticSearch 모델

분류에서Dev

MVC 아키텍처-사용자 지정 논리가있는 필드를 모델에 추가

분류에서Dev

MVC 아키텍처-사용자 지정 논리가있는 필드를 모델에 추가

분류에서Dev

이미 존재하는 모델에 gem 'devise'를 사용할 때 오류 발생

분류에서Dev

Django-확장 사용자 모델에서 필드를 가져 오는 Queryset

Related 관련 기사

  1. 1

    두 사용자 모델 (Devise, CanCan)에 대해 Rails alias_method에서 current_user로

  2. 2

    Rails / Devise-프로필 빌드에 사용자 이름 전달

  3. 3

    강력한 매개 변수를 사용하여 Rails 4의 Devise 사용자 모델에 사용자 정의 필드를 추가 할 수 없습니다.

  4. 4

    사용자 필드가있는 모델에 Django 저장

  5. 5

    Devise + 관련 프로필 모델-오류를 반환하는 프로필 페이지 표시

  6. 6

    Devise / Rails를 사용하여 모델에 UserID 전달

  7. 7

    표시 : Devise in rails 앱을 사용하여 프로필 양식의 가입 양식에있는 이름

  8. 8

    사용자 모델에 프로필을 생성하고 포함하는 방법 (사용자 모델 설계)?

  9. 9

    Devise로 생성 된 모델에 데이터 추가를 저장할 수 없습니다 (모델명 : user).

  10. 10

    devise 모델에 더 많은 필드를 추가하고이를 위해 form_for 사용

  11. 11

    Rails-Devise : 사용자가 로그인 할 수 있는지 확인

  12. 12

    Rails 4 has_many : through association : 다른 부모 모델에서 Devise current_user 사용 after_create 콜백

  13. 13

    Rails : Devise에서 사용자를 자동으로 기억할 수 있습니까?

  14. 14

    사용자 프로필 모델 쿼리

  15. 15

    devise는 여러 모델에서 어떻게 작동합니까?

  16. 16

    Rails, Devise 다중 모델 로그인 및 세션

  17. 17

    Rails, Devise 다중 모델 로그인 및 세션

  18. 18

    사용자 모델에서 액세스 할 수있는 '사용자 이름'속성을 만들 수 없음 (레일 4-Devise)

  19. 19

    Devise Rails에서 로그인시 직접 사용자

  20. 20

    Devise로 내 사용자 모델에 외부 관계를 추가 한 다음 업데이트하려고합니다.

  21. 21

    Rails Devise는 로그인시 사용자를 추가합니다.

  22. 22

    Flask : 모델을 파일에 연결 (예 : 프로필 사진)

  23. 23

    Rails, Devise-관리자가 다른 사용자 프로필을 편집하려고합니다. 대신 자신의 프로필이로드되었습니다.

  24. 24

    Rails-Devise-별도의 테이블에 프로필 정보 추가

  25. 25

    필드가있는 Rails ElasticSearch 모델

  26. 26

    MVC 아키텍처-사용자 지정 논리가있는 필드를 모델에 추가

  27. 27

    MVC 아키텍처-사용자 지정 논리가있는 필드를 모델에 추가

  28. 28

    이미 존재하는 모델에 gem 'devise'를 사용할 때 오류 발생

  29. 29

    Django-확장 사용자 모델에서 필드를 가져 오는 Queryset

뜨겁다태그

보관