将first和lastname都收集到一个全名

时间:2016-01-15 20:33:31

标签: angularjs asp.net-mvc model-view-controller

我开始使用我的第一个角度应用程序,这样当我将名字写成名字和姓氏时,我必须展示全名。

我的意思是少数名字和姓氏,并指出整个全名。现在问题是它根本不添加全名。

UsersCreate.js - (我确定故障就在这里

var UserCreatenNow = angular.module('UserCreatenNow', []);

UserCreatenNow.controller('CreateUserNow', function ($scope) {
    //checking on first name and surname are written.
    if ($scope.name != null && $scope.lastname != null)
    {
        //prints it together
        $fullname = "Welcome to " + $scope.name + " " + $scope.lastname;
    }
});

Create.cshtml

<div ng-app="UserCreatenNow" ng-controller="CreateUserNow">
<div class="form-group">
                <div class="col-xs-12">
                    @Html.LabelFor(u => u.Fornavn)
                    @Html.TextBoxFor(u => u.Fornavn, new
               {
                   @class = "form-control",
                   @ng_model = "name",
                   @placeholder = HelperTextClass.HelperText.placeholderInfo.Fornavn
               })
                    @Html.ValidationMessageFor(u => u.Fornavn, "", new
               {
                   @class = "label label-danger"
               })
                </div>
            </div>

            <div class="form-group">
                <div class="col-xs-12">
                    @Html.LabelFor(u => u.Efternavn)
                    @Html.TextBoxFor(u => u.Efternavn, new
               {
                   @class = "form-control",
                   @ng_model = "lastname",
                   @placeholder = HelperTextClass.HelperText.placeholderInfo.Efternavn
               })
                    @Html.ValidationMessageFor(u => u.Efternavn, "", new
               {
                   @class = "label label-danger"
               })
                </div>
            </div>
<div class="form-group">
    <div class="col-xs-12">
         <p class="label label-danger"></p>
         <button type="submit" class="btn btn-effect-ripple btn-success"><i class="fa fa-plus"></i> Create user {{fullname}}</button>
    </div>
</div>
</div>

1 个答案:

答案 0 :(得分:1)

Devise::InternalHelpers不在范围内。试试这个:

class Api::SessionsController < Devise::SessionsController
  prepend_before_filter :require_no_authentication, only: [:create]
  include Devise::InternalHelpers

  before_filter :ensure_params_exist

  def create
    build_resource
    resource = User.find_for_database_authentication(email: params[:email])
    return invalid_login_attempt unless resource

    if resource.valid_password?(password: params[:password])
      sign_in("user", resource)
      render(json: {success: true, auth_token: resource.auth_token, login: resource.email})
      return
    end
    invalid_login_attempt
  end

  def destroy
    sign_out(resource_name)
  end

  protected
    def ensure_params_exist
      return unless params[:email].blank?
      render(json: {success: false, message: "missing email parameter"}, status: 422)
      return unless params[:password].blank?
      render(json: {success: false, message: "missing password parameter"}, status: 422)
    end

    def invalid_login_attempt
      warden.custom_failure!
      render(json: {success: false, message: "Error with your login or password"}, status: 401)
    end

  private
    def create_params
      params.permit(:email, :password)
    end
end