意外的keyword_do_block

时间:2011-10-16 23:45:18

标签: ruby-on-rails

以下代码段可以正常使用我的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:在`require':/ app / app / console / lab1pd1am_controller.rb:1:语法错误,意外的keyword_do_block,期待';'或'\ n'(SyntaxError)

1 个答案:

答案 0 :(得分:0)

在你做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组合以清理它。