Created
March 17, 2014 17:33
-
-
Save jwo/9604213 to your computer and use it in GitHub Desktop.
Possible Additions to Chapter 7.2 of Angularails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app="AngulaRails" ng-controller="WidgetController" ng-init="setWidget(<%= @widget.to_json %>);"> | |
<%= form_for @widget, id: "widgetForm", html: { name: "widgetForm", "novalidate" => true, "ar-submit" => true } do |f| %> | |
<% if @widget.errors.any? %> | |
<div class="alert alert-danger"> | |
<h4><%= pluralize(@widget.errors.count, "error") %></h4> | |
<ul> | |
<% @widget.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="form-group" ng-class="{ 'has-error': widgetForm['widget[name]'].$invalid }"> | |
<%= f.label :name %> | |
<%= f.text_field :name, class: "form-control", "ng-model" => "widget.name", required: true, "ng-minlength" => "7" %> | |
<span class="help-block" ng-show="widgetForm['widget[name]'].$error.required">Required</span> | |
<span class="help-block" ng-show="widgetForm['widget[name]'].$error.minlength">Minimum length of 7</span> | |
</div> | |
<div class="form-group" ng-class="{ 'has-error': widgetForm['widget[price]'].$invalid }"> | |
<%= f.label :price %> | |
<%= f.number_field :price, class: "form-control", "ng-model" => "widget.price", required: true, "min" => "10" %> | |
<span class="help-block" ng-show="widgetForm['widget[price]'].$error.required">Required</span> | |
<span class="help-block" ng-show="widgetForm['widget[price]'].$error.min">Most be greater than 10</span> | |
</div> | |
<%= f.submit "Save", class: "btn btn-primary", "ng-disabled" => "widgetForm.$invalid" %> | |
<% end %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
//= require jquery | |
//= require jquery_ujs | |
//= require twitter/bootstrap | |
//= require angular | |
//= require angular-application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AngulaRails.controller "WidgetController", ($scope) -> | |
$scope.widget = {} | |
$scope.setWidget = (record) -> | |
$scope.widget = record |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ng-controller="WidgetController"
to specify the controller we want to link to