Ruby rails应用程序控制器中的SyntaxError
我将twitter引导库用于我的新SimpleRails应用程序 并使用了一些脚手架作为产品模型 我更新了GemFile、bundle命令和railsgbootstrap。 当我运行网页时,出现以下错误:Ruby rails应用程序控制器中的SyntaxError,ruby,ruby-on-rails-3,twitter-bootstrap-rails,Ruby,Ruby On Rails 3,Twitter Bootstrap Rails,我将twitter引导库用于我的新SimpleRails应用程序 并使用了一些脚手架作为产品模型 我更新了GemFile、bundle命令和railsgbootstrap。 当我运行网页时,出现以下错误: SyntaxError in ProductsController#index /Library/Ruby/Gems/1.8/gems/twitter-bootstrap-rails-2.1.4/app/helpers/glyph_helper.rb:9: syntax error, une
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...
我不知道为什么会这样
这是我的档案:
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
class ProductsController@products}
结束
结束
#获取/products/1
#GET/products/1.json
def秀
@product=product.find(参数[:id])
回应待办事项|格式|
format.html#show.html.erb
format.json{render:json=>@product}
结束
结束
#获取/产品/新
#GET/products/new.json
def新
@product=product.new
回应待办事项|格式|
format.html#new.html.erb
format.json{render:json=>@product}
结束
结束
#获取/产品/1/编辑
定义编辑
@product=product.find(参数[:id])
结束
#邮政/产品
#POST/products.json
def创建
@product=product.new(参数[:product])
回应待办事项|格式|
如果@product.save
format.html{redirect_to@product,:notice=>“产品已成功创建”。}
format.json{render:json=>@product,:status=>:created,:location=>@product}
其他的
format.html{render:action=>“new”}
format.json{render:json=>@product.errors,:status=>:unprocessable_entity}
结束
结束
结束
#PUT/products/1
#PUT/products/1.json
def更新
@product=product.find(参数[:id])
回应待办事项|格式|
if@product.update_属性(参数[:product])
format.html{redirect_to@product,:notice=>“产品已成功更新”。}
format.json{head:no_content}
其他的
format.html{render:action=>“edit”}
format.json{render:json=>@product.errors,:status=>:unprocessable_entity}
结束
结束
结束
#删除/products/1
#删除/products/1.json
def销毁
@product=product.find(参数[:id])
@产品销毁
回应待办事项|格式|
format.html{redirect_to products_url}
format.json{head:no_content}
结束
结束
结束
解决方案似乎很简单。我猜您正在使用的某些gem版本需要ruby版本>1.9.0,因为它具有符号功能,所以您可以执行bar:foo
而不是:bar=>foo
因此,如果您改为ruby 1.9.2或1.9.2,这个问题就会消失 实际上,您的错误来自
content\u标记:i,nil,class:names.map{name |“icon-{name
并且它不在您的控制器中,您使用的是什么ruby版本?我使用的是ruby 1.8.7此错误的解决方案是什么?谢谢!