link-to

undefined method 'link_to'

你离开我真会死。 提交于 2019-12-03 10:01:46
I'm writing a ruby-on-rails library module: module Facets class Facet attr_accessor :name, :display_name, :category, :group, :special ... URI = {:controller => 'wiki', :action => 'plants'} SEARCH = {:status => WikiLink::CURRENT} #Parameters is an hash of {:field => "1"} values def render_for_search(parameters) result = link_to(display_name, URI.merge(parameters).merge({name => "1"})) count = WikiPlant.count(:conditions => (SEARCH.merge(parameters.merge({name => "1"})))) result << "(#{count})" end end ... end when I call render_for_search I get the error undefined method 'link_to' I've tried

Rails 4 Data Toggle link_to

廉价感情. 提交于 2019-12-03 08:48:16
问题 How can I use the link_to method in Rails 4 to provide the same effect as <a href="(mysite.example.com)" class="tooltips" data-toggle="tooltip" data-placement="top" title="" data-original-title="Facebook"> 回答1: <%= link_to 'my site', 'mysite.example.com', { :class => 'tooltips', 'data-toggle' => 'tooltip', 'data-placement' => 'top', :title => '', 'data-original-title' => 'Facebook' } %> Or <%= link_to 'my site', root_path, class: 'tooltips', title: '', data: { toggle: 'tooltip', placement:

Rails :confirm modifier callback?

不想你离开。 提交于 2019-12-03 05:54:18
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 documentation . By following the link_to source, I see that the :confirm modifier is passed to the

adding a class to a link_to is breaking the link

≯℡__Kan透↙ 提交于 2019-12-03 05:35:55
问题 I'm using link_to in RoR 3 When I use it like this, it works fine: <%= link_to "Add to your favorites list",:controller => 'favourite_companies', :action =>'create', :company_id=>"#{@company.id}", :company_name=>"#{@company.company_name}" %> But I would like to pass in a class as well however, this is not working for me. The class works, but it breaks the link. Any ideas? <%= link_to "Add to your favorites list",{:controller => 'favourite_companies', :action =>'create'}, :company_id=>"#{

create a link_to in controller

旧巷老猫 提交于 2019-12-03 03:19:36
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. if you are using rails 3, you can use view_context.link_to(...) in your controller. UPDATE: with the format.html code format.html do redirect_to

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

北城以北 提交于 2019-12-03 02:21:53
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. This is a good case for writing your own helper that wraps the link_to. In your application_helper.rb you can write a method active_link_to that takes the same params as link_to + current_page, and then just calls

Rails 4 Data Toggle link_to

落花浮王杯 提交于 2019-12-03 00:25:42
How can I use the link_to method in Rails 4 to provide the same effect as <a href="(mysite.example.com)" class="tooltips" data-toggle="tooltip" data-placement="top" title="" data-original-title="Facebook"> <%= link_to 'my site', 'mysite.example.com', { :class => 'tooltips', 'data-toggle' => 'tooltip', 'data-placement' => 'top', :title => '', 'data-original-title' => 'Facebook' } %> Or <%= link_to 'my site', root_path, class: 'tooltips', title: '', data: { toggle: 'tooltip', placement: 'top', original_title: 'Facebook' } %> Or <%= link_to 'my site', { controller: 'home', action: 'index' }, {

Why are my links not working for my ruby on rails site? Links stay on same page when clicked on

时光毁灭记忆、已成空白 提交于 2019-12-03 00:11:12
问题 My links aren't working for my ruby on rails site. When I click the link the site stays on the same page. I'm following code from a book called: "RailsSpace: Building a social networking site with ruby on rails" By Michael Hartl. The book is available free for download you can follow the code for yourself, its on pages 55-56 starting under the title "adding navigation". Here is a link to the ebook. Thanks for your help. I tried googling the "link_to" function and changing the format, all it

Rails 3 - link_to with image_tag + text

痴心易碎 提交于 2019-12-02 22:26:17
<%= link_to ((image_tag 'image.png'), url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true) %> This part of code will generate me image.png as a link. I would need to this image append some text (image + text), I tried something like a: <%= link_to ((image_tag 'image.png', 'text'), url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true) %> And similar ways, but each of these attempts ended with an error message about bad syntax... Could anyone help me, please, how I should set it right?

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

断了今生、忘了曾经 提交于 2019-12-02 17:05:37
问题 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,