link-to

RAILS link_to external site, url is attribute of user table, like: @users.website

只谈情不闲聊 提交于 2019-11-27 11:31:44
问题 I'm working on a website that allows users to create an account. One of the attributes when creating a user is a users personal website. When I try to use the users website like this: <%= link_to @user.site, @user.url %> The url that gets generated is: http://0.0.0.0:3000/www.userswebsite.com I think this is because of the @user part of the link_to... but how can I get this to link to www.userwebsite.com ? 回答1: Looks like you need to stick the protocol on your link. E.g. you have www

link_to delete url is not working

狂风中的少年 提交于 2019-11-27 04:33:08
问题 I have the following link_to delete url in my app <%=link_to "Delete",blog_path(@blog.id), :method => :delete, :class => "delete", :confirm => "Are you sure ?"%> It does not seem to be working.When I click this url, it just takes me to the show path.Can someone please tell me how to fix this. Thanks. 回答1: Are you using jQuery? If so, I think the problem could be that you are using jQuery without the updated rails.js file. Download rails.js here: https://github.com/rails/jquery-ujs/raw/master

How do I defined a variable link_to to an external URL

只谈情不闲聊 提交于 2019-11-27 02:03:01
问题 On my site a user has a personal profile with a link to his personal external website. The url of the sites I store in a postgresql database under the name website . When I test the result, I always get a url like this: http://localhost:3000/www.example.com instead of http://www.example.com My view index.html.erb looks like this: <% provide(:title, 'All projects') %> <h1>All projects</h1> <%= will_paginate %> <ul class="microposts"> <%= render @microposts %> </ul> <%= will_paginate %> and my

The better way to pass the foreign_key value to the Rails controller

六月ゝ 毕业季﹏ 提交于 2019-11-26 22:25:21
问题 It's been almost a week since I've began to dig deeper in forms , associations , hashes , symbols... But it seems I cannot solve the puzzle without your help . I am working on a project for displaying different galleries content . The basic idea is when the user sees the names of galleries (names are links ) to be able to click on chosen one. Then all the images ,that belong to this gallery , are displayed . On the bottom there should be a link "Add image in this gallery" . My models : class

file download link in rails

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 18:35:28
I would like to give visitors the option to download some pdf. I have tried: <%= link_to "abc", "/data/abc.pdf"%> <%= link_to "abc", "/data/abc.pdf", :format => 'pdf' %> and some variations but they don't seem to work. I keep getting No route matches [GET] "/data/abc.pdf" I have the pdf files in a folder called data, located in the assets folder. Any help would be appreciated. Rails 4: in routes: get "home/download_pdf" in controller (already have pdf): def download_pdf send_file( "#{Rails.root}/public/your_file.pdf", filename: "your_custom_file_name.pdf", type: "application/pdf" ) end in

Using Rails link_to for links that post

纵饮孤独 提交于 2019-11-26 15:39:22
问题 I have a link that I need to submit a post request with. Normally, I'd use jQuery and prevent the link's default behavior and then submit a form to the destination. This seems like something Rails should be able to help me out with. Sure enough, the link_to method has an option for specifying a POST http method: link_to "Profile", 'http://example.com/profile', method: :post That works, but I need to add 2 parameters too. I tried: link_to "Profile", 'http://example.com/profile', method: post,

file download link in rails

会有一股神秘感。 提交于 2019-11-26 06:29:10
问题 I would like to give visitors the option to download some pdf. I have tried: <%= link_to \"abc\", \"/data/abc.pdf\"%> <%= link_to \"abc\", \"/data/abc.pdf\", :format => \'pdf\' %> and some variations but they don\'t seem to work. I keep getting No route matches [GET] \"/data/abc.pdf\" I have the pdf files in a folder called data, located in the assets folder. Any help would be appreciated. 回答1: Rails 4: in routes: get "home/download_pdf" in controller (already have pdf): def download_pdf send