link-to

“render :nothing => true” returns empty plaintext file?

落爺英雄遲暮 提交于 2019-11-30 06:11:28
问题 I'm on Rails 2.3.3, and I need to make a link that sends a post request. I have one that looks like this: = link_to('Resend Email', {:controller => 'account', :action => 'resend_confirm_email'}, {:method => :post} ) Which makes the appropriate JavaScript behavior on the link: <a href="/account/resend_confirm_email" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; var s = document.createElement(

link_to :action => 'create' going to index rather than 'create'

◇◆丶佛笑我妖孽 提交于 2019-11-30 04:49:22
I am building a fairly simple recipe app to learn RoR, and I am attempting to allow a user to save a recipe by clicking a link rather than through a form, so I am connecting the user_recipe controllers 'create' function through a link_to. Unfortunately, for some reason the link_to is calling the index function rather than the create. I've written the link_to as <%= "save this recipe", :action => 'create', :recipe_id => @recipe %> this link is on the user_recipes/index.html.erb and is calling the 'create' function of the same controller. It doesn't seem to make a difference if I include the

rails link_to :remote

有些话、适合烂在心里 提交于 2019-11-29 20:07:57
I have the following: <%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %> <i class="icon-trash"></i> <% end %> which brings up a Bootstrap Modal for confirmation, and I wanted to hook onto the ajax call that so that I can display a spinner or some kind of text. I know that I can use unobtrusive javascript to listen to the click event like so, if I DON'T use ':remote => true' in my link_to jQuery -> $('.link-delete').live 'click', (event) -> $('.link-delete').html("Loading...") #THE

Submit form using link_to in rails

Deadly 提交于 2019-11-29 18:11:49
问题 I'm trying to submit a form using link_to as follows: <%= form_for(@post, :url=> '/post/action', :method=> 'post', :html => {:id=>'form_id'} ) do |f| %> .... <%= link_to 'submit', "/post/action", :onclick=>"document.getElementById('form_id').submit()" %> .... but it is not posting the form, it is simply redirecting my form to the specified url. Does anyone know how to do this? 回答1: You can use: <%= link_to 'submit', "#", :onclick => "$('#form_id').submit()" %> if you are using JQuery and a

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

好久不见. 提交于 2019-11-29 11:48:17
问题 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 ? 回答1: 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 %> 回答2: The simplest way to do it is by using html_safe or raw functions <%= link_to 'Log In<span class="button-right"><

How to add confirm message with link_to Ruby on rails

我的未来我决定 提交于 2019-11-29 10:31:44
问题 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? 回答1: 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

link_to syntax with rails3 (link_to_remote) and basic javascript not working in a rails3 app?

大城市里の小女人 提交于 2019-11-29 08:04:40
i am wondering if the basic link_to syntax is completely broken in current rails3 master or if i am doing some wrong syntax here. = link_to "name", nil, :onlick => "alert('Hello world!');" should actually produce an alert on click. very simple. does not work on my rails3 project! (also no error output!) any ideas? for the general link_to syntax i could not find an example where i could combine a link_to_remote with a confirmation, remote and html class (see my try below) = link_to "delete", {:action => "destroy", :remote => true, :method => :delete, :confirm => "#{a.title} wirklich Löschen?" }

Ruby on Rails: How to pass parameters from view to controller with link_to without parameters showing up in URL

吃可爱长大的小学妹 提交于 2019-11-29 07:41:48
问题 I am currently using a link_to helper in View to pass parameters like title , author ,image_url and isbn back to controller <%= link_to 'Sell this item',new_item_path(:title => title, :author => authors, :image_url=>image, :image_url_s=>image_s, :isbn=>isbn, :isbn13=>isbn13 ) %> Controller will then assign the parameters to an object to be used by a form in View later(in new.html.erb) def new @item = Item.new @item.title = params[:title] @item.author = params[:author] @item.image_url = params

Why Rails “link_to” does not work for delete action?

蹲街弑〆低调 提交于 2019-11-29 04:11:29
In index.html.erb I display all products, and next to each product I have Edit and Delete actions: <% @products.each do |product| %> ... <%= link_to("Edit", edit_product_path(product.id), :class => 'action') %> <%= link_to("Delete", product, :method => :delete, :class => 'action') %> ... <% end %> The Edit link works ok. However, the Delete link does not work. I get the following error: Unknown action The action 'show' could not be found for ProductsController I guess it is because the request method is GET rather than DELETE. But, I don't know why this happens if I set explicitly :method =>

How to use the link_to helper to open a popup?

橙三吉。 提交于 2019-11-28 21:38:19
I just want to use link_to to open a popup. I tried something but it doesn't work: <%= link_to 'Create a new company', new_company_path, :popup => ['create_company', 'height=600, width=600'] %> <br/> Any idea? Thanks! My first stab at this problem would probably look something like this. It assumes you're using rails 3, jQuery and jquery-rails. If you're not, this approach definitely won't work. This exact code isn't tested, so your mileage may vary. I'm just trying to give you an idea on how you might want to think about the problem. If you'd like me to elaborate on how this works, or have