recently i addded mobile screens to my application, after that respond_to block is not wroking
mime_type.rb
Mime::Type.register_alias "text/html", :mobile
Mime::Type.register "applications/xls", :xls
controller
def index
@customer_ord = CustomerOrder.all
respond_to do |format|
format.html
format.csv #{send_data @customer_ord.to_csv}
format.xls #{send_data @customer_orders.to_csv(col_sep: "/t")}
format.pdf end end
pdf, xls links in view
<%= link_to "PDF", customer_orders_path(format: "pdf"), :target => 'blank'%>
<%= link_to "CSV", customer_orders_path(format: "csv")%>
<%= link_to "EXCEL", customer_orders_path(format: "xls")%>
after adding mime type mobile, i am using separate mobile screens. in mobile version of application respond_to block not working.
for json methods also it was not working, i have
respond_to do |format|
format.json { render json: @price_prod.price }
end
i changed it to
render json: @price_prod.price
it is working now, but for pdf,xls generation is not working, please help
it was responding to mobile format only as i have this code in my application controller
def prepare_for_mobile
session[:mobile_param] = params[:mobile] if params[:mobile]
request.format = :mobile if mobile_device?
end
i changed it to
def prepare_for_mobile
session[:mobile_param] = params[:mobile] if params[:mobile]
if mobile_device? && request.format == :pdf
request.format = :pdf
elsif mobile_device? && request.format == :xls
request.format = :xls
elsif mobile_device? && request.format == :csv
request.format = :csv
elsif mobile_device?
request.format = :mobile
end
end
it worked for me, but there may be a better way to resolve it.