rails download file if I know file name - ruby-on-rails

I have read some questions like this Rails download file from show action?, but there are kind of confusing me.
I have file terms.docx. It is completely public. I want to show user a link to download it (for example Terms and conditions)
I can put it in public folder if needed but I can't find this folder in my rails project.
So How do I do this?

Yeah, just put file in the public folder which is located in root folder as #Nithin said and
Terms and conditions
Will do fine.

In your view, you can add:
<%= link_to "Terms and conditions", "/terms.docx" %>
In this case, the 'terms.docx' file should be placed in your public directory.
This will generate the link:
Terms and conditions

Related

How to give image path in ruby on rails

I want to use an image that is located in app/assets/revolution/assets/01.png.
I'm not using the by default app/assets/images folder. I want to use my own folder name 'revolution' where I'v made my own assets folder.
How do I give the image path in my index view? I'm trying to do it like this:
<%= image_tag ('revolution/assets/01.png') %>
You need to put that revolution folder in assets path first then you will be able access files from it.
config.assets.paths << Rails.root.join("app/assets", 'revolution')
Than only you will be able to access file from assets path like below.
<%= image_tag('01.png') %>
If you do not want to put your folder in assets images path. We have 2 ways of doing same. Either move your folder to assets/images or to public path (rails ways) in both way you can easily access file.
I think what you need is the helper asset_url
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_url
But you would strongly advise you to use the default folder if you want to do that.
#mudasobwa While it's true, you don't have to be such a d..k in your reply :/. It's not as if we never coded shit when discovering new languages / libs / concepts
#Gagan Gami
You could, but you would then avoid the asset pipeline and are going to have a huge cache problem with your browser the day you replace your file while keeping the name.

overriding front template translations doesn't work

I'm working on prestashop and I'm Trying to override "order detail page" in front (customer's details orders).
This is how I did :
I copied file \controllers\front\OrderDetailController.php into folder \override\controllers\front\OrderDetailController.php
I copied also default template file order-detail.tpl into folder override/customtemplate/order-detail.tpl
And In OrderDetailController.php I have specified template directory like that
$this->setTemplate(_PS_OVERRIDE_DIR_ . '/themes/parfum_evo/order-detail.tpl');
I tried, it works fine except translations. Even watching the documentation, no test solution seems to work.
Could anyone help me? Thank you in advance :'(
The php override sits in the correct place. As for the other, you specified the path the override/customtemplate/order-detail.tpl but then placed it in override/themes/parfum_evo/order-detail.tpl. I take it as customtemplate is farfum_evo really, but you need to add another one named themes, after override, using that structure. I think. Because there is a hook named
DisplayOverrideTemplate
Which should take care of this, while I believe setTemplate for controllers will always grab from the main theme folder

How to get the public path in Perl Dancer

Probably a silly question, but how do I get the path to the /public folder in Dancer?
I want to store/read csv files under the public folder, but don't know if Dancer offers any convenience methods to get the base path to the public folder.
The error I get when trying to create a file by saying:
open(FILE, ">>", "myapp/public/file.csv") or die "$!";
is:
No such file or directory in /ur/share/perl5/Dancer/Handler.pm l. 98
I'm not sure why it's going to Handler.pm?
My first answer is, don't do it that way...for two reasons:
You're potentially opening up a security issue. What if somehow a hacker figures out a way to write to your environment files, change your passwords, etc.?
You really want your /public files to be static, for version control, portability, etc.
That being said, if you really still want to do this, the public dir lives in config->{public}:
print "Public dir:".config->{public}."\n";
Source:
http://search.cpan.org/~xsawyerx/Dancer-1.3110/lib/Dancer/Config.pm#public_%28directory%29

Rails add file via controller

In the controller my Rails project, I would like to create a new file /public/my_files/welcome.txt with content
Welcome to my website!
(The folder my_files does not exist yet.)
How can I do that?
(Edit: I know that to make a static page, I don't need to do it via a controller. I'm actually making a dynamic page, but I'm just simplifying the example.)
File.open(Rails.root + '/public/my_files/welcome.txt', 'w') {|f|
f.write("your dynamic data") }
This is the simplest way you can create a file. Ruby will automatically create the file if not present. Let me know if this fits within your requirment.
I am not really sure what you asking about, but if you just want a static page you can do so without using the controllers
Just make a folder in the public dir (right click >> new >> folder) and make a html file in it.
Then start the rails server and point your browser to
localhost:3000/my_files/welcome.html

how to save text in app_resource. asp net mvc c# metatags

I have all my text inside view coding. I preffer to save it in app_resources, because i would to add other languages in future, and its look quite cleaner.
I just know that I need to use metatags in my view for text to connect it with file app_resource. How to it correctly, could you show me some examples how it looks like in view??
Thanks a lot and take care,
Ragims
You only need to create App_LocalResources folder in the same folder where you hold your views. Then give a name to zzz.resx. And then you can call resources in your view via zzz.
Example: *You have folder Contact in your View Folder.
Your add App_LocalResources to Contact folder. Then you give a name Contact.resx to your .resx file.
Finally in the view you can use <%= ContactResources.Contact.Index_ContactWithUs %> where Contact.Index_ContactWithUs - name of concrete resource.
Don't forget that in resources settings you can modify access type (Internal or Public).

Resources