我剛剛完成ARRS的實施,後面R.貝茨Railscasts#364。 我在放映視圖Rails應用程序活動記錄聲譽系統錯誤來電ID
這是與R完全不同的改變它適合我的應用程序,所以
用戶選票上的影片。貝茨之一,在索引視圖
而且在啓動上俳句
用戶投票,按鈕看起來不錯,他們在展會上亮相視圖。
然而當我點擊一個這個錯誤出現
名爲id的零,這將被錯誤地4 - 如果你真的想零的ID,請使用OBJECT_ID
任何想法任何人?
Movies_controller.rb
class MoviesController < ApplicationController # GET /movies # GET /movies.json def index @search = Movie.search(params[:q]) @movies = Movie.all end # GET /movies/1 # GET /movies/1.json def show @movies = Movie.find_with_reputation(:votes, :all, order: 'votes desc') @search = Movie.search(params[:q]) @movie = Movie.find(params[:id]) end def search @search = Movie.search(params[:q]) @movies = @search.result respond_to do |format| format.html # index.html.erb format.json { render json: @movies } end end # GET /movies/new # GET /movies/new.json def new @search = Movie.search(params[:q]) @movie = Movie.new end # GET /movies/1/edit def edit @search = Movie.search(params[:q]) @movie = Movie.find(params[:id]) end # POST /movies # POST /movies.json def create @search = Movie.search(params[:q]) @movie = Movie.new(params[:movie]) respond_to do |format| if @movie.save format.html { redirect_to @movie, notice: 'Movie was successfully created.' } format.json { render json: @movie, status: :created, location: @movie } else format.html { render action: "new" } format.json { render json: @movie.errors, status: :unprocessable_entity } end end end # PUT /movies/1 # PUT /movies/1.json def update @search = Movie.search(params[:q]) @movie = Movie.find(params[:id]) respond_to do |format| if @movie.update_attributes(params[:movie]) format.html { redirect_to @movie, notice: 'Movie was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @movie.errors, status: :unprocessable_entity } end end end # DELETE /movies/1 # DELETE /movies/1.json def destroy @movie = Movie.find(params[:id]) @movie.destroy end def vote value = params[:type] == "up" ? 1 : -1 @movie = Movie.find(params[:id]) @movie.add_evaluation(:votes, value, current_user) redirect_to :back, notice: "Thank you for voting!" end end
Movie.rb
has_reputation :votes, source: :user, aggregated_by: :sum
User.rb
has_reputation :votes, source: {reputation: :votes, of: :movies}, aggregated_by: :sum
show.html.erb //電影
<div class="ratings"> <em> <%= pluralize @movie.reputation_for(:votes).to_i, "vote" %> | <%= link_to "up", vote_movie_path(@movie, type: "up"), method: "post" %> | <%= link_to "down", vote_movie_path(@movie, type: "down"), method: "post" %> </em> </div>
的routes.rb
resources :movies do member { post :vote } end
你可以添加相關的代碼到你的問題? – fontno
Okk做到了嗎?再也沒有代碼或者是一切嗎? – PMP
你可以發佈你的'routes.rb'嗎?跟蹤中的錯誤是什麼? – fontno