customers_controller.rb
def export
@customers =Customer.all
flash[:success] = "Script ran successfully"
end
当错误消息说syntax error,expected keyword_do,expecting keyword_end flash[:success]="Script run successfully"do|format|^时,这意味着什么。我正在尝试使用flash成功方法从数据库中导出一个cvs文件。我看了看铸造的铁轨,但这对我解决这个问题没有帮助index.html.erb
<p><%= button_to 'export Import', scripts_export_data_path %></p>
检查语法并读取错误(正如Zabba在评论中提到的)。你会想要类似的东西:
respond_to do |format|
format.csv { render text: @customers.to_csv }
flash[:success] = "Script ran successfully"
end
请注意,有一个end
和respond_to
块。请务必阅读您的错误消息,因为它们非常有用。