gpt4 book ai didi

ruby-on-rails - 意外的 keyword_do_block

转载 作者:行者123 更新时间:2023-12-03 22:40:43 25 4
gpt4 key购买 nike

以下代码片段适用于我的 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: syntax error, unexpected keyword_do_block, expecting ';' or '\n' (SyntaxError)

最佳答案

在你执行 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 组合以进一步清理它。

关于ruby-on-rails - 意外的 keyword_do_block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7788150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com