link-to

Rails: method for 'standardizing' url input from users?

可紊 提交于 2019-12-04 12:20:06
I'd like Users in my Rails app to be able to share a link to their personal website in their profile. Simple enough, I have a column called website and a text field they can fill in to make it work. However, when I display this in a view there's a problem. If I use the link_to helper then whether or not the person included the http:// determines whether or not the url will work. But, if I automatically prepend http:// then I get it twice for users who DID put it in their url. I'm sure this is a fairly common problem, but I haven't been able to find any good blog posts or SO questions that

Rails :confirm modifier callback?

我是研究僧i 提交于 2019-12-04 10:29:56
问题 I want to call a javascript function that will be conditional upon a user's response to the confirm box. For example, I have the following anchor: <%= link_to 'Sign Out', destroy_session_path, confirm: 'Are you sure that you would like to sign out?', method: :delete %> Should I just abandon the unobtrusive javascript and bind my own jQuery callback to my anchor? Or is there some magical way to pass a callback function to the Rails url helper? I did not see any discussion of callbacks in the

Every link_to on my rails 4 application is being called twice

人盡茶涼 提交于 2019-12-04 05:44:44
I'm experiencing some unusual behaviour with my Rails 4 Application. Every single-time I click on a link_to inside my views, my controllers actions are being called twice. For example: In my root_url I have this standard call for users_profile : <%= link_to('User Profile', users_profile_path, :class => "logout-button") %> When I click this link, my console shows the following output: Started GET "/users/profile" for 127.0.0.1 at 2013-11-25 20:45:53 -0200 Processing by Users::SessionsController#profile as HTML User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 45 ORDER BY

Rails 3.1 link_to not showing confirmation or destroying properly

匆匆过客 提交于 2019-12-04 03:35:07
问题 I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while. In 10.4.2, Michael Hartl uses the following code to delete users: <%= link_to "delete", user, :method => :delete, :confirm => "You sure?", :title => "Delete #{user.name}" %> It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user

Using link_to in a class in a Rails helper

时光怂恿深爱的人放手 提交于 2019-12-04 03:07:18
I have a rails helper using the structore below, but when I use it I get the message undefined method 'link_to' The helper is arranged as: module MyHelper class Facet def render_for_search link_to("Value", params) end end class FacetList attr_accessor :facets def initialize #Create facets end def render_for_search result = "" facets.each do |facet| result << facet.render_for_search end result end end end This is because within the Class Facet you don't have access to the template binding. In order to call the render_for_search method you probably do something like <%= Facet.new.render_for

Button_to uses POST Link_to uses GET, why? ROR

穿精又带淫゛_ 提交于 2019-12-04 03:02:37
I've ran into a ror problem using the link_to. Why does my link to use the GET method and my button_to use the POST method, after I specified my "method"=>"post" within the link_to parameters? View: <%= button_to "pdf", :action => 'getquote' %> <%= link_to 'pdf', {:controller => 'inventories', :action => 'getquote', :method => :post } %> Controller Method: def getquote @cart = find_cart respond_to do |format| format.pdf end end Terminal Output (Button/Link, respectively): Processing InventoriesController#getquote (for 127.0.0.1 at 2010-01-30 01:38:02) [POST] Parameters: {"action"=>"getquote",

Rails 3.2.2 with Twitter Bootstrap Tabs Ajax not working

时光毁灭记忆、已成空白 提交于 2019-12-03 21:15:57
I'm on my second app with Rails and I want to get ajax working. I'm also using the tabs from bootstrap 2. There are two variations of the tabs for bootstrap that I found, one gives you the tabs and you can put the content of those tabs into DIVs, the other is basically each tab you are able to use a link. I opted for the latter so that I could Ajaxify the links. The basic idea is that my apps home page has tabs across the top such as: Home, Inventory, Tasks, etc...and when you click the tab it puts you at each of those controllers index page. I have this working perfectly fine until I try to

Add an 'active' class to all active links in rails?

北城以北 提交于 2019-12-03 12:45:23
问题 Basically, I have a lot of code that looks like this: link_to t('.profile'), business_path(@business), class: '#{'active' if current_page? business_path(@business)}' which isn't very DRY. I was wondering if anyone knows a good way to modify the link_to helper itself to automatically add an 'active' class to all links to the current page. If it helps, I'm open to using HAML or SLIM. 回答1: This is a good case for writing your own helper that wraps the link_to. In your application_helper.rb you

ruby on rails link_to delete method not working

£可爱£侵袭症+ 提交于 2019-12-03 12:41:35
I am trying to delete a post using the code below: <%= link_to 'Destroy', post, :method => :delete, :onclick => "return confirm('Are you sure you want to delete this post?')" %> which does not work... it simply redirects me back to the post (posts/:id} however, if i use the following code it works <%= button_to 'Destroy', post, method: :delete, :onclick => "return confirm('Are you sure you want to delete this post?')" %> is it possible to make link_to behave as button_to in this case? EDIT: destroy controller function def destroy @post = Post.find(params[:id]) @post.destroy respond_to do

create a link_to in controller

强颜欢笑 提交于 2019-12-03 11:58:04
问题 I need to pass a notice to a view from controller, and I want if can to create some link also to the notice. My controller: format.html { redirect_to purchase_order_headers_path, notice: 'PO already has RR with RR ID: ' + rr.rr_id + ', void RR first.' } Is there any way so I can do it so the [rr.rr_id] will become a link so when the user click on it will go to it's page? Since link_to will return error "undefined method" if put on controller. Thanks. 回答1: if you are using rails 3, you can use