Rendering an HTML file in rails - ruby-on-rails-3

I am using CarrierWave to upload static HTML templates to certain user profiles on my webpage.
I am trying to render the HTML file on the user's home page once they log in. The Path for the HTML file after uploading is:
/uploads/profile/curation/8/User_Content.html
I'm new to rails and I thought I'd just be able to
<%= render /uploads/profile/curation/8/User_Content.html %>
to get the html to render, but I guess that only works for partials, which this is not.
Any advice?

You can use render_to_string. Please have a look over here. http://russbrooks.com/2009/11/18/embed-a-static-hmtl-page-in-a-rails-view

In your controller you can redirect to the page you want:
redirect_to "/uploads/profile/curation/8/User_Content.html"

Related

Make the template folder if angular be functional as views folder

I'm trying to use the erb template on my angular templates folder, but the functionality is limited, for example,
The <% link_to
is working
but devise methods or even raw('sdmdslkc') pops an error that the method is not found.
for example
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
work on views but not in angular templates (says destroy_user_session_path method not found)
Whats missing ? is it fixable?
let me see if i understand, u have some template with some tags that belongs to another language that is not angular, html, or js. if so then it is not fixable because angular sends an ajax to bring that html file and injects it to your page, alot after any server has rendered any part of the page.
my suggestion for a work around is to try and tell angular to take a server page, say it was with asp.net and i would like some server tags i would tell angular that the template is somepage.aspx while making sure that my page evetually returns plain html.

How to show images of links in profile

I think this is a simple problem but I do not know how to phrase it to get a sample solution from a search engine.
Instead of allowing profile image uploads/gravatars on my website I would like to store links to images in the profile db table and embed those images in the profile show page view.
My initial thought is just to have a string url filed in the db. From there I do not know how rails will parse the string url and render the image.
Any suggestions are greatly appreciated.
If you have a link to the image stored as a link on the profile, then in your view you could do something like this:
Add image_link to Profile model
In controller
def show
#profile = Profile.find(params[:id])
....
end
In view
<%= image_tag #profile.image_link %>

How to use send_file in RoR

I'm very new to RoR and am trying to use send_file to have users download and view files that were uploaded by other users. I want to have a link on the project show page for each of the uploaded files. For now I am uploading the files using carrierwave and storing them in public/uploads/permit/avatar/permit_id/file. After going through much documentation I can't seem to figure out exactly what code to put into the model view and controller to get the links to show up on the show page. Can some one please help me with what code to put where.
if you want allow only authorithed users download files then you should set other path than public, something like:
private/uploads/permit/avatar/permit_id/file
and use something like send_file avatar.uploader_field.file in controller action then in views:
link_to "avatar", path_to_controller_action
For everyone:
link_to "avatar", avatar.uploader_field.url
or
link_to "avatar", avatar.uploader_field.path
in views

Render a page as a saved HTML file using Rails 3.0?

I'm building a simple website generator application in Rails 3.0. I'd like a "publish" action in a controller that works just like an ordinary "show" action, but instead, saves a page as an HTML file in the "public" directory instead of displaying it in the browser. That is, I'd like to use the Rails render mechanism to create a file instead of providing an HTTP response.
What's the best way to do this?
Should I simply add caches_page :publish to the controller?
Or use render_to_string and File.new?
You can use render_to_string method: http://apidock.com/rails/AbstractController/Rendering/render_to_string
You still need to respond from the controller though. Maybe redirect to the page you just saved?
I would go with page caching.
Then if you have editable content, the pages should be automatically generated. You could then write a system task which bundles them up as a web site.
see (whatever)/actionpack/lib/action_controller/caching/pages.rb for instructions.
I found that page caching using caches_page won't work for me because there is no way to show a notification or redirect to another page after caching the page. The method render_to_string (suggested by #Grocery) is the way to go. Here's the example controller code:
def publish
#article = Article.find(params[:id])
html = render_to_string(:template => "articles/template.html.haml", :layout => 'article' )
FileUtils.makedirs("#{Rails.root}/public/articles/") unless File.exists?("#{Rails.root}/public/articles/")
File.open("#{Rails.root}/public/articles/#{#article.filename}.html", 'w') {|f| f.write(html) }
respond_to do |format|
format.html # publish.html.erb
end
end

Rails 3 rendering iframe with raw()

So I am storing the whole embed code from youtube into my database and then outputting it like this.
<%= raw(people.video) %>
which outputs the general iframe tag copied from youtube:
<iframe src="foo" width=400 height=380></iframe>
the problem is that it actually displays that tag instead of embedding the video into the page itself. I can get around this just by storing the src in the database.... but this is part of a mini cms system and the site admins would find it much easier just to copy and past the embed code from youtube. Is there someway I can specify for the iframe to actually render instead of just spitting out the html on the page?
You can use the raw method to render the HTML of a string, are you storing it that way? You can also try the RedCloth gem - I was able to get this working like so:
<%= raw RedCloth.new(#page_content.content).to_html %>
Which allowed for my custom CMS to use the Textile markup
http://en.wikipedia.org/wiki/Textile_%28markup_language%29
I'm not 100% on what you're seeing, since raw should render HTML, but you might also try to include the embed tag using a JavaScript.write, since there are some issues related to Flash objects embedded in HTML vs JavaScript.
Let me know if this doesn't work, and if so, can you provide screenshots or copy what you're seeing on the page?