2013-10-10 3 views
1

레일 만약 내가 3 개 모델세 가지 모델을 사용하여 다른 조건이

사용자 한 :에서

을 USER_ID, ID, 작업 ID : ID, 이름

채용 정보 : 아이디, USER_ID, 제목

응용 프로그램 작업 # show page 작업에 적용하지 않았거나 작업을 생성하지 않았고 로그인 한 사람들에게만 보이는 버튼을 넣으려고합니다. 나는 장치를 사용하고있다. 나는이 모델들 (SO 덕분에)에서 다음과 같이 올바른 관계를 구축 할 수 있었다.

user.jobs는 양식을 제출 버튼을 보여줍니다 다른 condtion이 (숨겨진 경우

jobs.applicants는 직장에서 모든 지원자를 #list

질문하는 방법을 공식화 한 사용자가 게시 한 모든 작업을 #list)를 job # show 페이지에 추가하고 job_id 및 user_id를 응용 프로그램 모델에 넣습니다.

은 내가 object.id 전무의 주위에 오류가 발생하는 방법에 대한 아이디어를 얻을 것으로 보인다 수 없습니다

<% if user_signed_in? %> 
<% if job.user_id = current_user.id %> 
    <div style="text-align:center;" class="widget"> 
    <%= link_to(new_user_session_path, :class => "g-btn type_primary") do %> 
     <i class="icon-external-link"></i> Apply for the job 
    <% end %> 
    </div> 
<% end %> 
<% end %> 

을 시도했다.

+0

에서 다음

resources :jobs do member do post 'apply' end end <% if user_signed_in? %> <% unless job.user == current_user %> <div style="text-align:center;" class="widget"> <%= link_to 'Apply', apply_job_path(job), method: :post %> </div> <% end %> <% else %> <%= link_to 'Sign in to apply', new_user_session_path %> <% end %> 

는 비교 할당 아니다. – Doon

답변

1

같은 조건이 어떻게 사용자가 작업에 적용되는 않는 경우 향상시킬 수 있습니까? 무슨 컨트롤러를 사용하니?

하면 코드는 다시 사용자 로깅,

이있는 사용자가 응용 프로그램 객체를 생성해야하고 사용자로부터 추가 정보가 필요 않는 프로세스를 완료, 또는이다 않는 기존 송신 정보의 라인을 따라 더 사용자가 작업에 저장된 정보로 이동합니다.

후자는 이와 같이 할 수 있습니다. 당신의 작업 컨트롤러 job.user_id = current_user.id 경우

def apply 
    if Application.create job_id: params[:job_id], user: current_user 
    redirect_to jobs_path, notice: "You have applied, good luck!" 
    else 
    ... do something for failure... 
    end 
end 
1

이 대신

<% if user_signed_in? %> 
    <% if job.user_id == current_user.id %> 
    <div style="text-align:center;" class="widget"> 
     <%= link_to "Apply for the job" new_user_session_path, :class => "g-btn type_primary" %> 
    </div> 
    <% end %> 
<% end %> 

을 시도하고이 라인을

<div style="text-align:center;" class="widget"> 

<div class="widget center"> 

에 변경과 관련 CSS 시트

center라는 클래스를 추가하는 것이 좋습니다 수 있습니다
+1

job.user_id = current_user.id <- 할당이 아니고 바로 – Doon

+0

인데, Doon – dax

2

= 표지판을 놓친 것 같습니다.

<% if user_signed_in? && job.present? && job.user_id == current_user.id %> 
    your logic here 
<% end %> 
관련 문제