'Rails 7.0.4 Error when in run some code of ruby on rails
no implicit conversion of Hash into String
class PostsController < ApplicationController @posts = Post.all
respond_to do |format|
format.html
format.csv { send_data @posts.to_csv }
format.xls { send_data @all.to_csv(col_sep: "\t")}
end
class Post < ApplicationRecord
def self.to_csv(options = {}) attributes_post = %w(title, description)
CSV.generate(options) do |csv|
csv << column_names
all.each do |post|
csv << post.attributes.values_at(*attributes_post)
end
end
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|