小编Pin*_*nou的帖子

修改请求参数的值

我想知道是否可以修改请求参数的值.

但我不知道该怎么做.

我试着用

$requestContent = $this->getRequest()->request->get('tactill_customerbundle_customertype');
Run Code Online (Sandbox Code Playgroud)

接下来我用

$request->request->replace()
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在我的情况下使用这种方法.

谢谢

symfony

25
推荐指数
1
解决办法
3万
查看次数

Rails 4 Angularjs Paperclip如何上传文件

我是新手用Rails 4操纵angularjs,它只提供api.我尝试创建一个简单的角度服务来上传文件.但我使用Paperclip来管理文件,我有一些问题.

首先,我不明白如何正确收集输入文件.我已经看到很多插件或胖指令来做到这一点.但我想要一个简单的指令收集我的文件并放入我的ng模型.

最后我想知道在Base64中编码我的文件是否更有效?

我的Rails控制器

class Api::EmployeesController < Api::BaseController
  def create
    employee = Employee.create(employee_params)
    if employee.save
      render json: employee
    else
     render :json => { :errors => employee.errors.full_messages }, :status => 406
     end
  end

  def employee_params
    params.require(:employee).permit(:first_name,:mobile_phone,:file)
  end
end
Run Code Online (Sandbox Code Playgroud)

我的Angularjs服务

angular.module('test').factory 'Employee', ($resource, $http) ->
 class Employee
  constructor: (errorHandler) ->
  @service = $resource('/api/employees/:id',
  {id: '@id'},
  {update: {method: 'PATCH'}})
  @errorHandler = errorHandler

  create: (attrs, $scope) ->
    new @service(employee: attrs).$save ((employee) ->
      $scope.employees.push(employee)
      $scope.success = true
      $timeout (->
        $scope.success = false
      ), 3000 …
Run Code Online (Sandbox Code Playgroud)

javascript file-upload paperclip angularjs ruby-on-rails-4

12
推荐指数
1
解决办法
9137
查看次数

获取 $state.current (ui-router) 进入 $http 拦截器

我正在努力实现的目标

我想在我的 $http 拦截器中获取当前状态的数据值。我已经创建了拦截器。

问题

我不知道如何在拦截器中捕获 $state.current.data。我尝试使用 $injector.get($state) 但无法读取对象的属性。

 angular.module('mymodule').factory 'HttpInterceptor', [
 '$location', '$injector'
  ($location, $injector) ->

  request: (config) ->
   # Do something when sending the request
   console.log(config.headers.hasOwnProperty('Authorization'))
   if config.headers.hasOwnProperty('Authorization') == false
    $location.url("/login")
   config
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-service angular-ui-router

5
推荐指数
1
解决办法
2882
查看次数

缺少当前文件夹Capistrano Rails 3.2

我需要理解为什么capistrano不会创建当前的文件夹.我正在使用以下命令:cap deploy:setup,cap deploy:check,cap deploy

但是,当我检查我的应用程序目录时,我不是当前文件夹.

这是我的deploy.rb

# Execute "bundle install" after deploy, but only when really needed
require 'bundler/capistrano'

# Automatically precompile assets
load "deploy/assets"

# RVM integration
require "rvm/capistrano"

# Application name
set :application, "app"

# Application environment
set :rails_env, :production

# Deploy username and sudo username
set :user, "ubuntu"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true


#We don't want to use sudo (root) - for security reasons

set :use_sudo, false

#Target ruby version

set :rvm_ruby_string, '1.9.3-p374'

#System-wide RVM installation …
Run Code Online (Sandbox Code Playgroud)

capistrano ruby-on-rails ruby-on-rails-3.2 rvm-capistrano

2
推荐指数
1
解决办法
4263
查看次数