How do I figure out the mime type without writing a file?
Assuming you are uploading file via html form, IO object should already have mime type, you can get it like that:
mime = params[:file].content_type
Render mime typed templates in Rails that are in a subfolder without explicitly providing the whole path in a render call
I was able to restructure the view folders by changing the default view path like suggested here.
show.html.erb rendering as plain text mime time
The Linux admin for my host said they are running a version of Mongrel where this is a known bug.
He put a newer version of mongrel.rb in my /config/initializers and that solved the problem.
Rendering a view with custom mime type in Grails
Do you have the accept
header in the request set the custom content-type?
The accept header is one way for client to inform server which content-type would be acceptable for itself.
In config.groovy
the below setting has to be set as well to use accept headers
grails.mime.use.accept.header = true
I would also try rendering the response in the conventional way:
render(contentType: "application/vnd.api+json", text: [message: 'some text', foo: 'bar'])
Setting view formats for custom mimetypes in Ruby on Rails?
I am going by your requirement that
I want this format to basically serve the same views as the .html format but with a different layout
I have a different approach that should work in Rails 3 (tested in Rails 3.2.12). Put the following in your controller:
before_filter do
@bare= (params[:format] == 'modal')
if @bare
params[:format]= 'html'
request.format= :html
end
end
layout :select_layout
# standard controller stuff
# ...
# Towards bottom of your controller code,
private
def select_layout
@bare ? 'bare' : nil
end
Summary:
- Change the format back to html.
- Set a variable to indicate that it needs to serve 'bare'
- Tell controller that value of layout will be given by a function. (See 'Choosing Layouts at Runtime' in http://guides.rubyonrails.org/layouts_and_rendering.html)
- No changes needed in any of the respond_to blocks.
This will do exactly what you need, i.e., same action as .html but with a different layout.
Related Topics
Is Time.Zone.Now.To_Date Equivalent to Date.Today
Adding a Submit Button Image to a Rails Form
Carrierwave - Resizing Images to Fixed Width
What Do the Fields of Ruby's Gc.Stat Mean
Use Global or Constant Variable in Ruby/Rails
Rvm Install: Ruby Installation Error
Subtract Dates in Ruby and Get the Difference in Minutes
How to Enable Tls for Redis 6 on Sidekiq
How to Get My Aws Lambda to Access Gems Stored in Vendor/Bundle
Differencebetween "Rails S" and "Bundle Exec Rails S"
What Is the Best Diff Library in Ruby
"Don't Run Bundler as Root" - What Is the Exact Difference Made by Using Root
Find Memory Leak in a Ruby on Rails Project
How to Remove Repeated Spaces in a String
Failing to Install Nokogiri Gem
Call Task More Than Once in Rails 3 Generator
Define_Method: How to Dynamically Create Methods with Arguments