0

I have a link in a Rails view such that when it's clicked on, I want it to call a particular method but NOT leave the page. I can get it to call the method but it always looks for a non-existent template.

I was told something like this would be possible with :remote => true, but it seems to completely ignore it. In the view (create.html.erb), it looks something like this:

<%= link_to 'Do something', foo_bar_index_path(:param1 => "value", :param2 => "value"), :remote => true %>

I have a defined route in routes.rb:

resources :bar do
   collection do
      get 'foo'
   end
end

In the 'bar' controller, it does call the "foo" method:

def foo
  # it does the stuff that's here
end

Then it gives me the following error:

Missing template bar/foo, application/foo with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/myrailspath/rails-root/app/views" 

How can I change this to still call the method but not leave the page?

shiggity
  • 531
  • 4
  • 12
  • Are you using jquery? you can use something like http://api.jquery.com/event.preventDefault/ to prevent link's default behavior click. – Leantraxxx Oct 01 '13 at 02:41

1 Answers1

1

Just check you have these two lines in your application.js

//= require jquery
//= require jquery_ujs
techvineet
  • 5,041
  • 2
  • 30
  • 28