簡體   English   中英

actions_as_taggable問題-一切看起來都很好

[英]acts_as_taggable issue - Everything looks almost fine

我剛剛逐步解決了另一個問題 ,但是我的應用仍在給我一些有關標記的錯誤(第4條)

Im遇到的錯誤是: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'

資源:用戶

傑克積極助手

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

索引方法缺少“結束”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM