Comments (7)
whether the forced stringifiement was intentional and is now a core ActionView expectation?
It kinda is yes. At least when there is multiple templates involved.
But I'll try to find some time to have a look if we could keep supporting the case outlined in the repro script (a single template that returns something responding to :each
).
from rails.
We are facing a similar issue with https://github.com/cheddar-me/rails-twirp at the moment - our rendering assigns the return value of the view to an instance variable via the ActionController rendering mechanics, but that return value is actually a Proto::Message
- not a rendered string, and that is deliberate. With 7.1 everything gets stringified, due to this bit in ActionView actually:
rails/actionview/lib/action_view/template.rb
Line 275 in f14401a
There is a forced string conversion that has been added with &.to_s
- since there is no specification on what render
must return or set exactly (what type) I wonder what the reasoning was for this change. For us this works correctly on 7.0x but broke on 7.1 and the only thing I could imagine we could do is subclass ActionView::Template
@eileencodes was there any decision made we should be aware of that "anything that renders must return strings or else" by any chance?
from rails.
As a result of git bisect
, the first commit that introduced this issue seems to be 4e8e828.
from rails.
Oh - thank you for the bisect @kuwabarahiroshi Interesting! @byroot could you help us out figuring out whether the forced stringifiement was intentional and is now a core ActionView expectation? Because it would mean that anything renderable must render strings 🤔
from rails.
That would be unfortunate because it means that it becomes impossible for a template to set a pre-filled object somewhere for later manipulation. While it will work for an enumerator, I wonder whether there should be a hook someplace where non-serialized rendered outputs could be accommodated. For example, in our library we generate a proto message and then either embed it inside another or manipulate it in some way (using after
of the controller and similar). One could say this is a corner case, but at the same time - ActionView used to allow this, and the behaviour changed. If we want to do some manipulation on protos for instance, we would then need to unmarshal them and then change them. Besides, protos are not streaming - so would be even less efficient 😢 Could there be a way to bypass the buffer path?
from rails.
As I said I'll have a look. In the meantime what would be useful would be to provide a repro script so I can see how hard it would be to restore that capability without losing the perf gains.
Unless of course the already provided Enumerator
example is representative enough of your use case.
from rails.
In my case, the real use case is to render CSV in view and returning as a streaming response.
# controllers/records_controller.rb
class RecordsController < ApplicationController
def index
@records = Record.all
end
end
# views/records/index.html.erb
# providing paginated view for html format
<% @records.page(params[:page]).each do |r| %>
<p><%= r.id %></p>
<% end %>
# views/records/index.csv.ruby
# providing all records for CSV format in streaming response
headers['Content-Disposition'] = "attachment; filename=records.csv"
Enumerator.new do |buff|
@records.find_each do |r|
buff << CSV.generate_line([r.id, r.name])
end
end
In this case, it'll be covered by @byroot 's proposal (a single template that returns something responding to :each
)
from rails.
Related Issues (20)
- no implicit conversion of String into Integer (TypeError) @env[name] HOT 2
- Relation `#distinct` doesn't raise an error for invalid arguments HOT 2
- ActiveModel::Dirty is broken in after_commit HOT 3
- Blocked hosts: site.com To allow requests to these hosts, make sure they are valid hostnames (containing only numbers, letters, dashes and dots), then add the following to your environment configuration: config.hosts << "site.com" For more details view: the Host Authorization guide HOT 2
- GlobalID::Locator.locate_signed cannot find SGIDs created in a Rails 6.1 app HOT 6
- New find_or_create_by behavior in Rails 7.1 can introduce subtransactions in PostgreSQL HOT 5
- Invalid route POST request results in key space error 500 instead of 404 HOT 2
- has_many through alias_method HOT 4
- create_table `force` option drops table when `if_not_exists` option is present
- Add a `--db-prepare` option to run check and run migrations when booting the server
- `DuplicableTest#test_duplicable` failure with ruby 3.4.0dev HOT 2
- Path traversal in AcitveStorage, and lead RCE (Need secret_key_base) HOT 1
- Add .test to default allowed host in development mode HOT 1
- Use ruby file: ".ruby-version" when possible HOT 6
- Exceptions raised from templates should show template code not compiled methods HOT 7
- Syntax errors are not presented correctly in ERB templates HOT 2
- Missing view template error page example does not account for nested controller paths HOT 1
- DatabaseTasks run in both development and test environments when RAILS_ENV=development HOT 3
- Rails 7.1.* Deserializes Date Range with Infinities incorrectly with Postgres adapter HOT 2
- ActionDispatch `recognize_path` trips over domain constraints HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.