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 %>
Related
I have an application in rails3 where i want to give user an option to choose a template from defaults (4 or 5 templates) to view his records.
the approach i am working on is to sent user on setting page from where he will select the template he want to use and on the basis of that setting the template will be rendered.
This looks simple but i am not sure this will work for me, please suggest me any alternative.
Please note i am talking about PDF formats.
Let's say you have a Setting model with a string attribute template.
You would let the user save the setting through a normal controller action.
Then on the controller where you want your pdf template to show, you could do something like this.
class MyController < ApplicationController
def show
#setting = Setting.find(params[:setting_id]) # Retrieve the setting instance
respond_to do |format|
format.pdf { render setting.template }
end
end
end
This will render the template named after the template the user has selected and is stored on setting as a string.
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"
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
I am building something where contributors can post content to my site. I want to create a link where other users can click on and bring the user to the respective contributor's own website. The permalink for each contributor's website is a column in my contributor model.
Everything I tried so far just appends the contributor's permalink to the end of the existing URL. ie, www.mysite.com/xxx/www.contributorsite.com instead of just redirecting to www.contributorcite.com
Please help
Try something like this (should probably build the link in the controller instead of model, or just append http:// to the user entered info):
<% link = "http://"+user.permalink %>
<%= link_to "Users website", link %>
I've added a custom engine into my refinery app with an image field. It all links up great and in the admin areas I can add images to it, etc.
I have a question about adding said images to a view however. At the moment I have the following code in a view:
<img src="<%= project.picture.url %>" alt="Image description" />
This displays my image nicely (although its probably not the best method - tips welcome) but I wanted to know how to access the thumbnail of that image. I noticed in others areas of refinery you can call a thumbnail method on an image object.
<%= image_fu image, ::Image.user_image_sizes[thumbnail.to_sym],
:class => "brown_border",
:class => "current_picked_image" %>
Please could someone run me through the steps of how to achieve this. The code snippet above comes out of the image_picker page code. Being quite new to rails I'm not sure how I would achieve this in my own page.
Thanks in advance for your help!
With image_fu:
<%=link_to (image_fu project.picture, '160x104'), project.picture.url %>