2016-10-28 6 views
0

Noob 외계인이 양식을 작성하려고합니다 belongs_to 관계. available assignsusers 변수를 추가하려면 어떻게해야합니까?ecto 사용자가 belongs_to association을 선택하십시오

컨트롤러 :

def new(conn, params) do 
    changeset = Project.changeset(%Project{}) 
    users = Repo.all(from(u in User, order_by: u.email, select: {u.email, u.id})) 
    Logger.debug "Controller: #{inspect users}" 
    render(conn, "new.html", changeset: changeset, users: users) 
    end 

형태 :

<%= form_for @changeset, @action, @users, fn f -> %> 
    <div class="form-group"> 
    <%= label f, :user_id, class: "control-label" %> 
    <%= Logger.debug "View 2: #{inspect @users}" %> 
    <%= select f, :user_id, @users, class: "form-control" %> 
    <%= error_tag f, :user_id %> 
    </div> 

오류 메시지 :

(ArgumentError) assign @users not available in eex template. 

Available assigns: [:action, :changeset] 

잘 큰, 나는이 (가) available assigns에 사용자를 추가하기 위해 노력하고있어.

답변

0

Derp. 이것은 레일에서도 마찬가지였다. 변수를 추가해야했습니다. new.html.eex

<h2>New project</h2> 

<%= render "form.html", changeset: @changeset, 
         action: project_path(@conn, :create), 
         users: @users %> 

<%= link "Back", to: project_path(@conn, :index) %>