ruby on rails - How do I show a static html file uploaded by user -


user can upload static html file on site.

i stored file paperclip.

but how show html in new window clicking link, without downloading it.

that's say. every user can upload resume file in html format

then can see resume click = user.find_by_id(id).resume.url

but don't want download html file.

i want open new window or hsow in current window or iframe

how ?

thanks~

it depends on how store them:

  1. if store html in database, can following:

    • add route:

      get '/resume/:id' => 'resume#show' 
    • create controller:

      class resumecontroller < applicationcontroller   def show     render html: resume_html(params[:id]).html_safe   end    private    def resume_html(id)     # here should return resume html either     # returning string     "<h1>resume</h1>"     # ... or reading file (this assumes utf8 encoding)     paperclip.io_adapters.for(user.find_by_id(id).resume).read.       pack('c*').force_encoding('utf-8')   end end 
  2. if store html file somewhere in publicly available place #{rails.root}/public, it's matter of issuing redirect in contoller (don't forget add route well):

    class resumecontroller < applicationcontroller   def show     redirect_to resume_path(params[:id])   end    private    def resume_path(id)     # whatever need return resume url/path   end end 

hope helps!


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -