2014-02-21 7 views
2

Project에 대한 폼 페이지가 있다고 가정하십시오.이 페이지는 namedescription입니다. render :partial을 살펴보십시오.(레일스에서) AngularJs에 부분 뷰를 사용하는 가장 좋은 방법은 무엇입니까?

<div class="page-header"> 
    <h2>{{project.id ? 'Edit ' : 'Add new'}} project</h2> 
</div> 

<div class="row"> 
    <div class="col-xs-6 col-xs-offset-2"> 
    <form class="form-horizontal"> 
     <%= render :partial => 'templates/forms/text', :object => 'name', :locals => {:model => 'project'} %> 
     <%= render :partial => 'templates/forms/text', :object => 'description', :locals => {:model => 'project'} %> 
     <div class="form-group"> 
     <div class="col-xs-offset-3 col-xs-9"> 
      <button ng-click="saveProject()" type="submit" class="btn btn-success">Submit</button> 
      <a ng-href="{{ path('UserIndexCtrl') }}" class="btn btn-default">Back</a> 
     </div> 
     </div> 
    </form> 
    </div> 
</div> 

그리고 부분적으로 사용됩니다.

<div class="form-group" ng-class="{'has-error': errors.<%= text.underscore %>}"> 
    <label for="<%= model %>.<%= text %>" class="col-xs-3 control-label"><%= text.titleize.humanize %></label> 
    <div class="col-xs-9"> 
    <input id="<%= model %>.<%= text %>" name="<%= model %>.<%= text %>" type="<%= local_assigns[:type] || 'text' %>" class="form-control" ng-class="{'text-danger': true}" ng-model="<%= model %>.<%= text %>"> 
    <span class="help-block" ng-show="errors.<%= text.underscore %>"><%= text.titleize.humanize %> {{errors.<%= text.underscore %>.join(', ')}}</span> 
    </div> 
</div> 

나는이 레일 + AngularJS와 콤보에 부분 렌더링을 할 수있는 적절한 방법입니다 확실하지 않다. 더 이상한 방법이 있다면 궁금해하니? 감사!

+0

은 반복 avoir, 좋아 보인다' <%= model %>. <%= text %>' – apneadiving

답변

0

내가 대신 HTML 직접 작성하는 입력을 생성하는 도우미를 사용하는 것이, 뭔가 같은 :

def input_for_model(model_name, text, options = { }) # I actually have no idea what is doing your input, you can probably find a better name 
    options = { id: "#{model_name}.#{text}", name: "#{model_name}.#{text}", 
       type: 'text', class: 'form-control', 
       ng-class: "{'text-danger': true}", 
       ng-model: "#{model_name}.#{text}" 
      }.merge(options) 
    tag(:input, options) 
end 

그리고 다음과 같이 사용 :

<div class="form-group" ng-class="{'has-error': errors.<%= text.underscore %>}"> 
    <label for="<%= model %>.<%= text %>" class="col-xs-3 control-label"><%= text.titleize.humanize %></label> 
    <div class="col-xs-9"> 

    <%= input_for_model(model, text, type: local_assigns[:type] || 'text') %> 

    <span class="help-block" ng-show="errors.<%= text.underscore %>"><%= text.titleize.humanize %> {{errors.<%= text.underscore %>.join(', ')}}</span> 
    </div> 
</div> 
관련 문제