유권자 ip_address가 투표를 제한하는 투표 시스템을 구현하려고합니다.IP 주소 당 하나의 투표
게시물 모델에 many_votes가 있고 투표가 게시물 모델에 속합니다.
제 질문은 어떻게 그리고 어디서 "current_user"를 정의하고 어떻게 뷰에서 구현할 수 있습니까? 사람을 제외하고
<%= link_to(post_votes_path(post), :method => 'post') do %>
<%= song.votes.size %>
작품 벌금 투표 할 수와 나는 그것을 중지하려면 :
현재 나는 다음과 같은 표를 작성하고 있습니다. 제발 내가 처음부터이 기능을 배우려고 노력하고있는 보석을 찾고 있지 않습니다.
건배. 조치를 생성하기위한
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to root_url, notice: 'Post was successfully created.' }
else
format.html { render action: "new" }
end
end
end
투표 컨트롤러 코드 : 고유 유효성 검사 제약 조건 ip
열에서
def create
@post = Post.find(params[:post_id])
@vote = @post.votes.create
respond_to do |format|
format.html { redirect_to root_url }
#format.js
end
end
사용자를 어떻게 저장하는지 말할 수 있습니까? – AnkitG
현재 사용자 테이블이 없습니다. 투표 테이블에 voter_id를 추가하려고합니다. – Joshua
투표 테이블에 'voter_ip'컬럼을 추가하고 유권자의 ip를 입력해야합니다 :'@ post.votes.create (voter_ip : request.remote_ip)'(변수'request'는 컨트롤러에서만 사용 가능합니다 , 요청을받을 때) @Gene이 말했듯이 투표 모델에'validates : voter_id, uniqueness : true'를 추가했다. – MrYoshiji