Ajax and js using link_to in Rails.I have a question about the erb call.

Asked 2 years ago, Updated 2 years ago, 62 views

I'm implementing a simple ajax call using link_to and remote: true

Ajax calls from erb to link_to in the same view folder are called well, so js.I'm good at loading erb files

A jax call called link_to within err called render :partial is strangely continuous to say that the template cannot be found.

So, looking at the server log, the link_to call within the same view is called processing as JS well.

The link_to call that says the template cannot be found goes into processing as HTML and keeps coming out as missing template.

I thought the route was twisted. Js.HTML instead of erb.I made the erb file and it's loaded well.

I searched with several keywords on the stack, but no answers solved whether I was not good at searching.

There were many answers to put response_to:js into the controller, but when I did it, I got an Unknown Format error, so I don't know what to do.

The structure of the project is as follows.

controllers/B_controller.rb

class BController < ApplicationController

  def action
    ...
    #respond_to:js #UnknownFormat Error
  end 

end

views/B/action.js.erb

...

views/A/foo.html.erb

...
<%= render :partial => "/C/nav" %>
...

views/C/_nav.erb

...
<% list.each do |item| %>
  <%= link_to 'Action', B_action_path(item), remote: true %>
<% end %>
...

ruby-on-rails ajax

2022-09-21 18:53

1 Answers

/views/B/action.js.If you change the directory name from uppercase B to lowercase b, the problem will be solved.

To be /views/b/action.js.erb


2022-09-21 18:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.