Solve the view path for the controller in Rails 3.2

I need a generic js (view) answer, which I visualize from a group of controllers. He lives in app/views/shared/success.js.erb.

This is the standard answer for most of my controllers, which modifies the DOM with some content. However, this content refers to the controller that runs it.

The problem is that I cannot figure out how to allow the view path for a specific controller from this general js view. He is an example (includes some controllers with names)

# app/controllers/users_controller.rb
class UsersController < ActionController::Base
  def create
    # do some stuff
    render 'shared/success' # .js.erb
  end
end

# app/controllers/settings/permissions_controller
class Settings::PermissionsController < ActionController::Base
  def create
    # do some stuff
    render 'shared/success' # .js.erb
  end
end

# app/views/users/success.html.erb
<p>Some View code that only relates to <strong>users</strong></p>

# app/views/settings/permissions/success.html.erb
<p>Some View code that only relates to <strong>permission settings</strong></p>

# app/views/shared/success.js.erb
var listItem = '<%= j render "#{insert resolved path to this particular controller instance}/success.html.erb" %>'
$(".list").append(listItem);

The reason I want to do this is because the js answer is always the same, it is just a change of content. Any thoughts on how I can get the current rendering path of the controller's default view?

+3
source
1

, :

params[:action]  

.

, .js, .

0

All Articles