acts_as_taggable issue - Everything looks almost fine

92 views Asked by At

I have just followed step by step this other question, but my app is still giving me some errors regarding tagging (rails 4)

Error that Im experiencing is: Desktop/hack/app/controllers/jacks_controller.rb:85: syntax error, unexpected end-of-input, expecting keyword_end end ^

I have already re-intended as suggested in the chat, but nothing changed.

Code for reference

I have no associations between my models, (in the link that I have referred, there are associations)

jack form

<%= 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

Routes Rails.application.routes.draw do

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'

resources :users

jack active helper

module JacksHelper 
include ActsAsTaggableOn::TagsHelper
end

And controller

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

There are 1 answers

4
Eyeslandic On BEST ANSWER

index method is missing an 'end'

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