acts_as_taggable问题 - 一切看起来都很好

时间:2014-06-06 21:32:36

标签: ruby-on-rails acts-as-taggable

我刚刚按照other question一步一步地进行了操作,但我的应用程序仍然给我一些关于标记的错误(rails 4)

我遇到的错误是:Desktop / hack / app / controllers / jacks_controller.rb:85:语法错误,意外的输入结束,期待keyword_end结束^

我已按照聊天中的建议重新打算,但没有任何改变。

参考代码

我的模型之间没有关联,(在我提到的链接中,有关联)

杰克表格

<%= form_for(@jack) do |f| %>
<% if @jack.errors.any? %>
<div id="error_explanation">
  <h2><%= pluralize(@jack.errors.count, "error") %> prohibited this jack from being saved:       </h2>

  <ul>
  <% @jack.errors.full_messages.each do |message| %>
    <li><%= message %></li>
  <% end %>
  </ul>
 </div>
 <% end %>

 <div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
 <div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :tag_list, "Tags (separated by comma)" %><br>
<%= f.text_field :tag_list %>
</div>
<div class="field">
<%= f.label :picture %><br>
<%= f.text_field :picture %>
</div>
<div class="actions">
<%= f.submit %>

   

jack.rb

class Jack < ActiveRecord::Base
    acts_as_taggable_on :tags

end

路线     Rails.application.routes.draw做

get 'tagged/index'

root :to => redirect('/jacks')

 get 'about' => "about#info"
 get 'submit' => "jacks#create"


 resources :jacks
match 'tagged', to: 'jacks#tagged', :as => 'tagged', via: 'get'

资源:用户

jack active helper

module JacksHelper 
include ActsAsTaggableOn::TagsHelper
end

和控制器

class JacksController < ApplicationController
before_action :set_jack, only: [:show, :edit, :update, :destroy]

# GET /jacks
# GET /jacks.json
def index
if params [:tag]
  @jacks = Jack.tagged_with(params[:tag])
else
  @jacks = Jack.all
end

# GET /jacks/1
# GET /jacks/1.json
def show
end

# GET /jacks/new
def new
@jack = Jack.new
end

# GET /jacks/1/edit
def edit
end

# POST /jacks
# POST /jacks.json
def create
@jack = Jack.new(jack_params)

respond_to do |format|
  if @jack.save
    format.html { redirect_to @jack, notice: 'Jack was successfully created.' }
    format.json { render :show, status: :created, location: @jack }
  else
    format.html { render :new }
    format.json { render json: @jack.errors, status: :unprocessable_entity }
     end
   end
 end

 # PATCH/PUT /jacks/1
 # PATCH/PUT /jacks/1.json
 def update
 respond_to do |format|
  if @jack.update(jack_params)
    format.html { redirect_to @jack, notice: 'Jack was successfully updated.' }
    format.json { render :show, status: :ok, location: @jack }
  else
    format.html { render :edit }
    format.json { render json: @jack.errors, status: :unprocessable_entity }
  end
  end
 end

 # DELETE /jacks/1
 # DELETE /jacks/1.json
def destroy
@jack.destroy
respond_to do |format|
  format.html { redirect_to jacks_url, notice: 'Jack was successfully destroyed.' }
  format.json { head :no_content }
 end
end

def tagged
if params[:tag].present? 
@jacks = Jack.tagged_with(params[:tag])
else 
@jacks = Jack.postall
 end      
 end

 private
  # Use callbacks to share common setup or constraints between actions.
  def set_jack
  @jack = Jack.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def jack_params
  params.require(:jack).permit(:title, :description, :picture, :tag_list)
 end
end

1 个答案:

答案 0 :(得分:1)

索引方法缺少'结束'

def index
  if params[:tag]
    @jacks = Jack.tagged_with(params[:tag])
  else
    @jacks = Jack.all
  end
end