Reputation: 513
I need to add customizable interface for each user in my app. So after some googling i decided to generate css, cache it for every user and link it in views. I found good post and used it as example.
So there is pieces of resulting code from my app:
In controller shedule_themes_controller.rb:
...
def get_css
respond_to do |format|
format.css { render :text => "body {\n background-color: blue; \n}", :content_type => Mime::CSS }
end
end
In layout:
...
<%= stylesheet_link_tag "application" %>
<link href="<%= get_css_path %>" media="screen" rel="stylesheet" type="text/css" />
But when i start application, the css doesnt't load. It comes 406 Not Acceptable Error. And response headers are:
Cache-Control:no-cache, private
Connection:Keep-Alive
Content-Length:1
Content-Type:text/html; charset=utf-8
So as you see, response has content/type text/html so 406 error is.
Can anyone explain me, why controller response with text/html if request content-type is text/css ?
P.S. I tried to manually send request to localhost:3000/get_css using Google Chrome DEV HTTP CLIENT. I set up Content-Type: text/css and server responded with right css and content-type:
body {
background-color: blue;
}
So probably i made some mistakes in linking dynamic css in my layout?
Thank you!
Upvotes: 1
Views: 1214
Reputation: 3083
The problem seems to be in the requested url. <%= get_css_path %>
will return /get_css
and hence the controller action with handle this request by the format.html
part. So you can try to append the format with the url as:
<link href="<%= get_css_path(:format => :css) %>" media="screen" rel="stylesheet" type="text/css" />
This will request /get_css.css
and hence the action will handle with format.css part.
Upvotes: 1