link-to

form_for being submitting by 2 links, how to I tell which was used when I am back in the controller?

ぐ巨炮叔叔 提交于 2019-12-02 11:20:33
I putting a form together, but for design reason the form must be submitted by a link. I found out how to perform that: = link_to_function "Next >>", "$(this).up('form').submit()" This will do, and I can create many link with this no problem. However I don't know how to distinguish which link was used to bring me back to the controller ? I need to perform slightly different depending on the link... Any idea ? I have tried to embed some javascript, etc. but I could not figure it out. Thanks, Alex = link_to_function "Next >>", "$('#hidden_field').value = 1;$(this).up('form').submit()" = link_to

Rails 3.1 link_to not showing confirmation or destroying properly

被刻印的时光 ゝ 提交于 2019-12-01 18:48:31
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 page. It is supposed to work if you include this: <%= javascript_include_tag :defaults %> but it fails

link_to update (without form)

自古美人都是妖i 提交于 2019-12-01 02:14:19
I want a link to update a resource, without using an HTML form. Routes : resources :users do resource :profile, :controller=>"profiles" resources :friends end Rake routes: user_friend GET /users/:user_id/friends/:id(.:format){:action=>"show", :controller=>"friends"} PUT /users/:user_id/friends/:id(.:format){:action=>"update", :controller=>"friends"} I want to use the put to update a friend by a simple link, something like this: <%=link_to "Add as friend", user_friend_path(current_user, :method=>'put')%> But as Rails meet that link he tries to go into the show action. The question is: what is

link_to update (without form)

独自空忆成欢 提交于 2019-11-30 21:42:37
问题 I want a link to update a resource, without using an HTML form. Routes : resources :users do resource :profile, :controller=>"profiles" resources :friends end Rake routes: user_friend GET /users/:user_id/friends/:id(.:format){:action=>"show", :controller=>"friends"} PUT /users/:user_id/friends/:id(.:format){:action=>"update", :controller=>"friends"} I want to use the put to update a friend by a simple link, something like this: <%=link_to "Add as friend", user_friend_path(current_user,

How to add article title to URL using link_to in Rails app?

╄→гoц情女王★ 提交于 2019-11-30 15:51:44
问题 I am trying to follow answer to question How to get link_to in Rails output an SEO friendly url? but don't get the result. In my Rails 3 app I have: # routes.rb match '/articles/:id/:title' => 'articles#show' resources :articles # articles/index.html.haml - @articles.each do |article| = link_to article.title, article, :title => article.title However, after restarting the server, the links don't have the title: /articles/1, /articles/2 What is wrong? 回答1: Your link_to will be using the route

link_to with jquery params in rails

孤街浪徒 提交于 2019-11-30 13:23:06
问题 I want to make an in-place search in my rails app. I used button_to_remote with prototype, but now I'm using JQuery, so I changed to link_to. This is my code: <%= link_to "Search", {:action => "geocode", :with => "'address='+$('#{address_helper_id}').value"}, :method => :post, :remote => true %> I want to pass the address textfield to my controller, but the output is not what I expected. /mycontroller/geocode?with=%27address%3D%27%2B%24%28%27record_location___address%27%29.value How do I

Rails 'link_to' to Download An Image Immediately Instead of Opening it in the Browser

依然范特西╮ 提交于 2019-11-30 08:15:18
I have a link_to Rails helper that downloads a wallpaper when clicked. But the image is loading in the browser instead of being downloaded immediately. <%= link_to "1920x1080", @download.wallpapers[1].wallpaper.url %> But at the same time I have a link_to Rails helper that downloads a screensaver of .exe format but here it works as inteded: file being downloaded immediately. <%= link_to "720p", @download.screensavers.first.screensaver.url %> What should I add or do so that the images will not be opened in the browser but instead be downloaded immediately? Thanks! Generally, the cleanest way to

Can I use a link_to to generate a link with a span inside?

半腔热情 提交于 2019-11-30 08:12:28
I am basically trying to get this result: <a href="#" class="button small-button green-button"> Log in <span class="button-right"></span> </a> But I don't know how to do this with a link_to in rails 3 ? You can use the block form of link_to for that: <%= link_to "#", :class => "button small-button green-button" do %> Log in <span class="button-right"></span> <% end %> The simplest way to do it is by using html_safe or raw functions <%= link_to 'Log In<span class="button-right"></span>'.html_safe %> or using raw function (recommended) <%= link_to raw('Log In<span class="button-right"></span>')

How to add confirm message with link_to Ruby on rails

核能气质少年 提交于 2019-11-30 08:03:49
I wanted to add confirmation message on link_to function with Ruby. = link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?' Any ideas why it's not working? First, you should verify that your layout have jquery_ujs . Best practice to do it by including it in your main application.js : //= require jquery_ujs Check that you included application.js in your layout: = javascript_include_tag :application While, in development mode, view your source html and verify jquery_ujs.js exists. Run your server and verify your link tag has data-confirm value, for example: <a href="/articles/1"

Ruby on rails 3 link_to controller and action

南笙酒味 提交于 2019-11-30 07:52:25
I know this is probably a pretty simple concept. I am trying to create a link to a controller and action. For example I have a link in my layout file to update a record when a link is clicked, so I need to be able to link to the controller and action. How would I accomplish this? link_to "Label", :controller => :my_controller, :action => :index See url_for . Also with CSS: <%= link_to "Purchase", { :controller => :transactions, :action => :purchase }, { class: "btn btn-primary btn-lg", style: "width: 100%;" } %> 来源: https://stackoverflow.com/questions/5607155/ruby-on-rails-3-link-to-controller