Передача @object в направляющие частичный рендеринг

Я разрабатывал Pork.dbObject самостоятельно. (Простой PHP ORM и Активная Рекордная реализация) главная причина состоит в том, что я нахожу большинство ORMs слишком тяжелый.

основная мысль о Pork.dbObejct должна быть легка и проста настроить. Никакой набор XML-файлов, всего один вызов функции в конструкторе обязать его, и addRelation или addCustomRelation определять отношение к другому dbObject.

Посмотрели на него: Pork.dbObject

20
задан David C 5 December 2009 в 02:26
поделиться

3 ответа

Why is it so important that you use an instance variable(variables who's names begin with '@', eg: @object) in your partial? It's not a good habit to get into. Using instance variables in partials complicates the control flow, which facilitates bugs and makes reuse of partials more difficult. This blog post explains the problem a little more in depth.

Really you have two options. The first option is the suggested solution.

  1. Change all instance variables to a local variable and pass it to the partial with the locals argument of render.

  2. Set the instance variable before the partial is rendered. Partials have access to all the instance variables that your controller sets.

Again instance variables in partials are bad. You should never set instance variables just because your partials are already written to use them. Rewrite the partial instead.

34
ответ дан 29 November 2019 в 23:04
поделиться

You could always do @profile = profile in the partial.

1
ответ дан 29 November 2019 в 23:04
поделиться

это проще

<%= render :partial => "profiles/show", :collection => @profiles %>

на частичном _show.html.erb

<%= profile.fullname %>

надеюсь помогло

1
ответ дан 29 November 2019 в 23:04
поделиться
Другие вопросы по тегам:

Похожие вопросы: