English 中文(简体)
解决铁路控制人的观点途径3.2
原标题:Resolve the view path for a controller in Rails 3.2

我想要得到一席之地的回答(观点)。 它生活在以下各条:申请/意见/共享/选择。

这是对我的控制人员 IX的一项标准答复,该答复对管理局作了一些改动。 然而,这一内容对于控制者来说尤为突出。

问题在于,我无法说明如何从这种共同的格言中解决特定控制者的观点。 他举了一个例子(包括一些名牌控制器)。

# 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);

我之所以要这样做,是因为对策总是一样的,它只是变化的内容。 对我如何看待目前的控制人员违约的看法,使之走上正轨的任何想法?

问题回答

您可使用以下手段查阅现行行动名称:

params[:action]  

然后,你可以相应地对观点进行定制。

Alternatively, you can just set an instance variable in these controllers with value you expect in the .js view, and just use it in the view.





相关问题
How to show some animation while control is rendering?

I have WPF ListBox that shows a lot of data. I need smooth scrolling, so I ve set ListBox.ScrollViewer.CanContentScroll to False that disables virtualization. Now when I open the tab where this ...

Font Rendering between Mozilla and webkit

I m not sure if this has anything to do with the recent Safari update, but I m beginning to notice this a lot. There is a drastic difference in the way each browser is rendering fonts. for instance, ...

How to render a printable image from a SWF

I m working on a project at the moment where the client uses an off-the-shelf Flash library to display data against a map. It s a SWF that we feed some XML data and it renders it in various ways, such ...

Load image into memory immediately

I need to open all frames from Tiff image in WPF into memory and then delete the source. And after that I eventually need to render that image (resized according to window size). My solution is quite ...

JSP programmatically render

I need to programmatically render JSP page. As far as I understand, JSP should have some compiler. The question is can I use this compiler dirrectly without JspServlet and others? All I need is ...

热门标签