视野中缺少第一个字段

时间:2015-01-07 06:24:34

标签: ruby-on-rails ruby

第一个字段“Cliche”拒绝显示,“description”字段正确显示。不确定我做错了什么。 enter image description here

common_linkers / show.html.erb

<div class="table-responsive">
  <table class="table">
    <tbody>
      <tr>
        <td><strong>Cliche:</strong></td>
        <td <%= @common_linker.cliche %></td>
      </tr>
      <tr>
        <td><strong>Description:</strong></td>
        <td> <%= @common_linker.description %></td>
      </tr>
      <tr>
        <td><strong>Created by:</strong></td>
         <td><%= @common_linker.user.email %></td> 
      </tr>

common_linkers_controller.rb

class CommonLinkersController < ApplicationController
  before_action :set_common_linker, only: [:show, :edit, :update, :destroy, :votes]
  before_action :set_movie
  before_action :authenticate_user!
  respond_to :html

  def index
    @common_linkers = CommonLinker.all
    respond_with(@common_linkers)
  end

  def show
    @common_linker = CommonLinker.find(params[:id])
  end

   def vote
      value = params[:type] == "up" ? 1 : -1
     @common_linker = CommonLinker.find(params[:id])
     @common_linker.add_or_update_evaluation(:votes, value, current_user)
      redirect_to :back, notice: "thanks for the vote"
   end


  def new
    @common_linker = CommonLinker.new
    respond_with(@common_linker)
  end

  def edit
  end

  def create
    @common_linker = CommonLinker.new(common_linker_params)
    @common_linker.user_id = current_user.id
    @common_linker.movie_id = @movie.id

    if @common_linker.save
        redirect_to @movie
    else
      render 'new'
    end
  end

  def update
    @common_linker.update(common_linker_params)
    respond_with(@common_linker)
  end

  def destroy
    @common_linker.destroy
    respond_with(@common_linker)
  end

  private
  def set_common_linker
    @common_linker = CommonLinker.find(params[:id])
    end

   def set_movie
      @movie = Movie.find(params[:movie_id])
   end

  def common_linker_params
    params.require(:common_linker).permit(:cliche, :description)
    end
end

common_linker.rb

class CommonLinker < ActiveRecord::Base
   belongs_to :user
   belongs_to :movie

   has_reputation :votes, source: :user, aggregated_by: :sum
end

的routes.rb

Rails.application.routes.draw do

  devise_for :users
  resources :movies do 
   resources :common_linkers do
      member { post :vote }

     end
  end
   root 'movies#index'


end

我还在学习,但我觉得我在这里错过了一些大事。任何帮助都会很棒。提前致谢。

1 个答案:

答案 0 :(得分:4)

错字:

<td <%= @common_linker.cliche %></td>

应该是:

<td> <%= @common_linker.cliche %></td>