2012-10-27 53 views
3

我使用Twitter的引導庫爲我的新的簡單的Rails應用程序 和使用的一些支架爲我更新的Gemfile以及捆綁命令和軌道摹引導產品型號 。 當我運行網頁,我收到以下錯誤:的SyntaxError在Rails應用程序控制器

SyntaxError in ProductsController#index 

/Library/Ruby/Gems/1.8/gems/twitter-bootstrap-rails-2.1.4/app/helpers/glyph_helper.rb:9: syntax error, unexpected ':' 
... content_tag :i, nil, class: names.map{|name| "icon-#{name... 

我不知道爲什麼會這樣!

這裏是我的Gemfile:

source 'https://rubygems.org' 

gem 'rails', '3.2.7' 

# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 

gem 'sqlite3' 

gem 'json' 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer', :platforms => :ruby 

    gem 'uglifier', '>= 1.0.3' 
    gem 'twitter-bootstrap-rails' 
end 

gem 'jquery-rails' 

控制器代碼:

class ProductsController < ApplicationController 
    # GET /products 
    # GET /products.json 
    def index 
    @products = Product.all 

    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render :json => @products } 
    end 
    end 

    # GET /products/1 
    # GET /products/1.json 
    def show 
    @product = Product.find(params[:id]) 

    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render :json => @product } 
    end 
    end 

    # GET /products/new 
    # GET /products/new.json 
    def new 
    @product = Product.new 

    respond_to do |format| 
     format.html # new.html.erb 
     format.json { render :json => @product } 
    end 
    end 

    # GET /products/1/edit 
    def edit 
    @product = Product.find(params[:id]) 
    end 

    # POST /products 
    # POST /products.json 
    def create 
    @product = Product.new(params[:product]) 

    respond_to do |format| 
     if @product.save 
     format.html { redirect_to @product, :notice => 'Product was successfully created.' } 
     format.json { render :json => @product, :status => :created, :location => @product } 
     else 
     format.html { render :action => "new" } 
     format.json { render :json => @product.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

    # PUT /products/1 
    # PUT /products/1.json 
    def update 
    @product = Product.find(params[:id]) 

    respond_to do |format| 
     if @product.update_attributes(params[:product]) 
     format.html { redirect_to @product, :notice => 'Product was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render :action => "edit" } 
     format.json { render :json => @product.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /products/1 
    # DELETE /products/1.json 
    def destroy 
    @product = Product.find(params[:id]) 
    @product.destroy 

    respond_to do |format| 
     format.html { redirect_to products_url } 
     format.json { head :no_content } 
    end 
    end 
end 
+0

其實你的錯誤來自'content_tag:i,nil,class:names.map {| name | 「icon - #{name',它不在你的控制器中 –

+0

和你使用的是什麼ruby版本? –

+0

我使用的是Ruby 1.8.7這個錯誤的解決方案是什麼?謝謝! – user1778530

回答

2

解決辦法似乎很簡單。我猜你使用的一些寶石的版本需要紅寶石版本> 1.9.0,因爲符號功能,所以你可以做bar: foo而不是:bar => foo

所以,如果你改變爲紅寶石1.9.2或1.9.2的問題將走開!

+0

工作。謝謝。 – user1778530

相關問題