下面的代码片段在我的Rails 3.0.3中运行良好:
class Lab1pd1amController < ApplicationController
def index
respond_to do |format|
@students = Student.find_by_sql("SELECT * FROM students WHERE students.session = 'AM' and students.pd1 = 'Science' ORDER BY lname ASC")
format.html # index.html.erb
format.xml { render :xml => @students }
end
end
def show
@students = Student.find(params[:all])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @student }
end
end
end但是,当我使用Heroku进行部署时,我会得到以下语法错误消息(在Heroku日志上):
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3 .0.3/lib/active_support/dependencies.rb:239:in‘`require':/app/app/controllers/lab1pd1am_controller.rb:1:语法错误,意外keyword_do_block,expecting’;或'\n‘(SyntaxError)
发布于 2011-11-07 21:00:28
在你做git push heroku master之前,我会确保有什么东西没有溜进去。
也需要清理一下。
class Lab1pd1amController < ApplicationController
def index
@students = Student.where(:session => "AM", :pd1 => "Science").order("lname ASC")
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @students }
end
end
def show
@student = Student.find(params[:all])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @student }
end
end
end您还可以将respond_to替换为respond_to/respond_with组合,以便更好地清理它。
https://stackoverflow.com/questions/7788150
复制相似问题