Remove controller action name from url












-1















I'm having what I feel might be a simple issue but am kind struggling with it. I have an action in my Controller that downloads a pdf when a button is clicked in the View. The PDF download but the issue is after I click it the action remains in the browser and downloads the PDF every time I reload the page.



Example of URL



Before I click button



https://matrix-spam-camp.c9users.io


After I click of the button this stays in URL until I delete it manually from the browser.



https://matrix-spam-camp.c9users.io/download_pdf


/app/app/views/portfolio/main.html.erb (link)



<%= link_to download_pdf_path, class: 'download-btn', remote: true do %>
<%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
<% end %>


/app/app/controllers/portfolio_controller.rb



def download_pdf
send_file "#{Rails.root}/app/assets/docs/resume.pdf", type: "application/pdf", x_sendfile: true
end


/app/config/routes.rb



get 'download_pdf', to: "portfolio#download_pdf"


Any help with this issue will be greatly appreciated.










share|improve this question























  • have you tried removing the remote true from the link?

    – xploshioOn
    Nov 27 '18 at 2:03











  • Yeah, unfortunately, its been doing this before I added remote: true.

    – Jumping Jack
    Nov 27 '18 at 2:10











  • then maybe it's the remote true that isn't working, do you have //= require rails-ujs on your application.js file? do you have other remote parts on your application that are working as expected?

    – xploshioOn
    Nov 27 '18 at 2:16











  • Yes, I have //= require rails-ujs in application.js. No, I this is the only remote item so far.

    – Jumping Jack
    Nov 27 '18 at 2:22
















-1















I'm having what I feel might be a simple issue but am kind struggling with it. I have an action in my Controller that downloads a pdf when a button is clicked in the View. The PDF download but the issue is after I click it the action remains in the browser and downloads the PDF every time I reload the page.



Example of URL



Before I click button



https://matrix-spam-camp.c9users.io


After I click of the button this stays in URL until I delete it manually from the browser.



https://matrix-spam-camp.c9users.io/download_pdf


/app/app/views/portfolio/main.html.erb (link)



<%= link_to download_pdf_path, class: 'download-btn', remote: true do %>
<%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
<% end %>


/app/app/controllers/portfolio_controller.rb



def download_pdf
send_file "#{Rails.root}/app/assets/docs/resume.pdf", type: "application/pdf", x_sendfile: true
end


/app/config/routes.rb



get 'download_pdf', to: "portfolio#download_pdf"


Any help with this issue will be greatly appreciated.










share|improve this question























  • have you tried removing the remote true from the link?

    – xploshioOn
    Nov 27 '18 at 2:03











  • Yeah, unfortunately, its been doing this before I added remote: true.

    – Jumping Jack
    Nov 27 '18 at 2:10











  • then maybe it's the remote true that isn't working, do you have //= require rails-ujs on your application.js file? do you have other remote parts on your application that are working as expected?

    – xploshioOn
    Nov 27 '18 at 2:16











  • Yes, I have //= require rails-ujs in application.js. No, I this is the only remote item so far.

    – Jumping Jack
    Nov 27 '18 at 2:22














-1












-1








-1








I'm having what I feel might be a simple issue but am kind struggling with it. I have an action in my Controller that downloads a pdf when a button is clicked in the View. The PDF download but the issue is after I click it the action remains in the browser and downloads the PDF every time I reload the page.



Example of URL



Before I click button



https://matrix-spam-camp.c9users.io


After I click of the button this stays in URL until I delete it manually from the browser.



https://matrix-spam-camp.c9users.io/download_pdf


/app/app/views/portfolio/main.html.erb (link)



<%= link_to download_pdf_path, class: 'download-btn', remote: true do %>
<%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
<% end %>


/app/app/controllers/portfolio_controller.rb



def download_pdf
send_file "#{Rails.root}/app/assets/docs/resume.pdf", type: "application/pdf", x_sendfile: true
end


/app/config/routes.rb



get 'download_pdf', to: "portfolio#download_pdf"


Any help with this issue will be greatly appreciated.










share|improve this question














I'm having what I feel might be a simple issue but am kind struggling with it. I have an action in my Controller that downloads a pdf when a button is clicked in the View. The PDF download but the issue is after I click it the action remains in the browser and downloads the PDF every time I reload the page.



Example of URL



Before I click button



https://matrix-spam-camp.c9users.io


After I click of the button this stays in URL until I delete it manually from the browser.



https://matrix-spam-camp.c9users.io/download_pdf


/app/app/views/portfolio/main.html.erb (link)



<%= link_to download_pdf_path, class: 'download-btn', remote: true do %>
<%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
<% end %>


/app/app/controllers/portfolio_controller.rb



def download_pdf
send_file "#{Rails.root}/app/assets/docs/resume.pdf", type: "application/pdf", x_sendfile: true
end


/app/config/routes.rb



get 'download_pdf', to: "portfolio#download_pdf"


Any help with this issue will be greatly appreciated.







ruby-on-rails ruby ruby-on-rails-5






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 1:47









Jumping JackJumping Jack

73




73













  • have you tried removing the remote true from the link?

    – xploshioOn
    Nov 27 '18 at 2:03











  • Yeah, unfortunately, its been doing this before I added remote: true.

    – Jumping Jack
    Nov 27 '18 at 2:10











  • then maybe it's the remote true that isn't working, do you have //= require rails-ujs on your application.js file? do you have other remote parts on your application that are working as expected?

    – xploshioOn
    Nov 27 '18 at 2:16











  • Yes, I have //= require rails-ujs in application.js. No, I this is the only remote item so far.

    – Jumping Jack
    Nov 27 '18 at 2:22



















  • have you tried removing the remote true from the link?

    – xploshioOn
    Nov 27 '18 at 2:03











  • Yeah, unfortunately, its been doing this before I added remote: true.

    – Jumping Jack
    Nov 27 '18 at 2:10











  • then maybe it's the remote true that isn't working, do you have //= require rails-ujs on your application.js file? do you have other remote parts on your application that are working as expected?

    – xploshioOn
    Nov 27 '18 at 2:16











  • Yes, I have //= require rails-ujs in application.js. No, I this is the only remote item so far.

    – Jumping Jack
    Nov 27 '18 at 2:22

















have you tried removing the remote true from the link?

– xploshioOn
Nov 27 '18 at 2:03





have you tried removing the remote true from the link?

– xploshioOn
Nov 27 '18 at 2:03













Yeah, unfortunately, its been doing this before I added remote: true.

– Jumping Jack
Nov 27 '18 at 2:10





Yeah, unfortunately, its been doing this before I added remote: true.

– Jumping Jack
Nov 27 '18 at 2:10













then maybe it's the remote true that isn't working, do you have //= require rails-ujs on your application.js file? do you have other remote parts on your application that are working as expected?

– xploshioOn
Nov 27 '18 at 2:16





then maybe it's the remote true that isn't working, do you have //= require rails-ujs on your application.js file? do you have other remote parts on your application that are working as expected?

– xploshioOn
Nov 27 '18 at 2:16













Yes, I have //= require rails-ujs in application.js. No, I this is the only remote item so far.

– Jumping Jack
Nov 27 '18 at 2:22





Yes, I have //= require rails-ujs in application.js. No, I this is the only remote item so far.

– Jumping Jack
Nov 27 '18 at 2:22












1 Answer
1






active

oldest

votes


















0














So I was able to solve this by adding a target: _blank to the link_to.



<%= link_to :download, class: 'download-btn', target: "_blank" do %>
<%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
<% end %>


This prevents the download button from applying the name for the controller action being called by the link_to from being placed in the browsers URL.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491604%2fremove-controller-action-name-from-url%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So I was able to solve this by adding a target: _blank to the link_to.



    <%= link_to :download, class: 'download-btn', target: "_blank" do %>
    <%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
    <% end %>


    This prevents the download button from applying the name for the controller action being called by the link_to from being placed in the browsers URL.






    share|improve this answer




























      0














      So I was able to solve this by adding a target: _blank to the link_to.



      <%= link_to :download, class: 'download-btn', target: "_blank" do %>
      <%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
      <% end %>


      This prevents the download button from applying the name for the controller action being called by the link_to from being placed in the browsers URL.






      share|improve this answer


























        0












        0








        0







        So I was able to solve this by adding a target: _blank to the link_to.



        <%= link_to :download, class: 'download-btn', target: "_blank" do %>
        <%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
        <% end %>


        This prevents the download button from applying the name for the controller action being called by the link_to from being placed in the browsers URL.






        share|improve this answer













        So I was able to solve this by adding a target: _blank to the link_to.



        <%= link_to :download, class: 'download-btn', target: "_blank" do %>
        <%= image_tag('img_btn_icon.png') %> <span class='resume-btn-text'>Resume</span>
        <% end %>


        This prevents the download button from applying the name for the controller action being called by the link_to from being placed in the browsers URL.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 3:38









        Jumping JackJumping Jack

        73




        73
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491604%2fremove-controller-action-name-from-url%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)