The error I am getting
NoMethodError (undefined method `reject' for #<ActionDispatch::Http::UploadedFile:0x007fab6ea5c370>):
app/controllers/photos_controller.rb:3:in `create'
The form (it's in HAML)
%form{:id => 'photo-upload-form', :method => 'post', :action => '/photos', :enctype => 'multipart/form-data'}
%input{:type => 'file', :id => 'photo', :name => 'photo'}
%input.btn{:type => 'submit', :value => 'Upload Photo'}
photos_controller.rb Controller
class PhotosController < ApplicationController
def create # POST /photos
photo = Photo.create(params[:photo])
render :nothing => true
end
end
photo.rb Model
class Photo
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :photo,
:storage => :s3,
:bucket => '<My_Bucket>',
:s3_credentials => {
:access_key_id => '<My_Access_Key>',
:secret_access_key => '<My_Secret_Access_Key>'
},
:styles => {
:thumb => "100x100",
:medium => "200x200",
:large => "600x400"
}
end
Gemfile (have run bundle install)
gem 'mongoid-paperclip', :require => "mongoid_paperclip"
gem 'aws-sdk'
Versions
Ruby 1.9.3
Rails 3.2.3
Mongoid 2.4.8
Mongoid-Paperclip 0.0.7
Paperclip 3.1.2
aws-sdk 1.5.7
The code is fairly simple and I've followed the docs. No idea what I should do.
So, the issue was
photo = Photo.create(params[:photo])
should have been
photo = Photo.create(params)
Now, I hope you'll excuse me as I go and kick myself. :)
Related
Upgraded CakePHP from 3.5 -> 3.6 -> 3.7. The error message, Property _transportConfig does not exist, is displayed as soon as the application starts in the browser.
Email Transport config in app.php
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => '*******#gmail.com',
'password' => '********************',
'log' => true,
'tls' => true
],
],
I've found some information in the migration guide, here is a solution that may work;
First, you need to add this to your bootstrap file
use Cake\Mailer\TransportFactory;
then replace
Email::setConfigTransport(Configure::consume('EmailTransport'));
by
TransportFactory::setConfig(Configure::consume('EmailTransport'));
finally you might consider updating the debugger via composer :
λ composer require --update-with-dependencies "cakephp/debug_kit"
Might not be the best way to, but it worked for me!
I am using the CakePHP plugin (https://github.com/t73biz/cakephp2-jwt-auth). My CakePHP app is version 2.6.2. I have added this to my Auth Component in the AppController.
'JwtAuth.JwtToken' => array(
'fields' => array(
'username' => 'email',
'password' => 'password',
'token' => '_token'
),
'parameter' => '_token',
'contain' => array(
'Organization'
),
'scope' => array(
'User.status' => 'A',
//'User.frozen' => 0,
'User.locked_out' => 0,
'Organization.status' => 'A',
//'User.failed_sign_ins < 4'
),
'header' => 'X_JSON_WEB_TOKEN',
'pepper' => 'pepper' // Says pepper because I do not want to show the pepper key I used for my code
),
I know that the plugin runs because I add a die statement in the getUser function in the plugin and it shows up when I do the API request.
public function getUser(CakeRequest $request) {
$token = $this->_getToken($request);
if ($token) {
return $this->_findUser($token);
}
return false;
}
This is the function that is part of the JwtTokenAuthenticate.php in the Component directory in the Controller directory of the plugin. When I debug $request, I do not get the header as part of the request. I am using Postman for testing the API and Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImlkIjoiMTIiLCJzdWIiOiIxMiJ9LCJpYXQiOjE0ODcyNTUxMjYsImV4cCI6MTQ4NzI1ODcyNn0.5hoyXltPmEXIA3eVtJnnn3Dor2lhviej31eZNbaMbow
If I understand you correctly you're trying to pass auth token via Authorization header? But according to the plugin docs you should be doing it either via X_JSON_WEB_TOKEN header or _token query param.
Please add below code inside your .htaccess file, it will work
<IfModule mod_rewrite.c>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>
I'm new to Drupal making a plugin that hooks into the ckeditor widget. I absolutely can't figure out why my implementation of a hook that is defined in ckeditor is never called.
Here are some details
my module is enabled
I'm able to use more basic hooks like exceltohtml_plugin instead of exceltohtml_ckeditor_plugin and reach my test statement.
I'm can't think of any more troubleshooting ideas to reveal the issue so any help would be greatly appreciated.
exceltohtml.module
<?php
error_log("TEST: this will print to log");
// implementation of hook_ckeditor_plugin()
function exceltohtml_ckeditor_plugin()
{
error_log("TEST: but this will never run");
return array(
'exceltohtml' => array(
'name' => 'exceltohtml',
'desc' => t('Excel sheet upload'),
'path' => drupal_get_path('module', 'exceltohtml') .'/plugins/exceltohtml',
'buttons' => array(
'excel_to_html' => array('label' => 'Insert spoiler','icon' => '/images/image.gif' ),
)
)
);
}
ckeditor.api.php (the file in ckeditor that Im basing my hook on)
/**
* Hook to register the CKEditor plugin
*/
function hook_ckeditor_plugin() {
return array(
'plugin_name' => array(
// Name of the plugin used to write it.
'name' => 'plugin_name',
// Description of the plugin - it would be displayed in the plugins management section of profile settings.
'desc' => t('Plugin description'),
// The full path to the CKEditor plugins directory, with the trailing slash.
'path' => drupal_get_path('module', 'my_module') . '/plugin_dir/',
'buttons' => array(
'button_name' => array(
'icon' => 'path to button icon',
'label' => 'Button Label',
)
)
)
);
}
If the function in your module is new, then the slightly older version of your module code might be cached.
Visit the module listing page in Drupal, that should reload the modules PHP code:
admin/modules
I am using following directory structure in Wamp server and i am getting an error Fatal error: Class 'Application_Model_ClassName' not found:
www--->pnp--->client--->application
--->controllers
--->modules
--->models
--->docs
--->library
--->public
--->.htaccess
--->.buildpath
But when i remove client directory from the above structure its working fine. With the following structure its working fine.
www--->pnp--->application
--->controllers
--->modules
--->models
--->docs
--->library
--->public
--->.htaccess
--->.buildpath
Please suggest, so that i can use client or dev or qa directory.
We need to autoload model files in the the Bootstrap.php, with the following code.
protected function _initAutoLoad ()
{
$autoLoader = Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(
array('basePath' => APPLICATION_PATH, 'namespace' => 'Application',
'resourceTypes' => array(
'form' => array('path' => 'forms/', 'namespace' => 'Form'),
'model' => array('path' => 'models/', 'namespace' => 'Model'))));
return $autoLoader;
}
I'm trying to provision a CentOS box using Vagrant and Chef Solo. I've specified some attributes I would like the apache2 cookbook to use but it does not appear to be using them.
Here's what I've added in my Vagrantfile:
chef.json.merge!(
'apache2' => {
'user' => 'testuser',
'group' => 'testgroup',
'dir' => '/custom',
'log_dir' => '/custom/logs/http',
'default_site_enabled' => false
}
)
chef.add_recipe "apache2"
Yet, after running vagrant up the apache cookbook has ignored all of the attributes I've specified. I've tried using both apache and apache2 as the key.
Am I missing something simple? Thanks!
This should merge the attributes into the node.
chef.json = {
'apache2' => {
'user' => 'testuser',
'group' => 'testgroup',
'dir' => '/custom',
'log_dir' => '/custom/logs/http',
'default_site_enabled' => false
}
}
And this is how you would access it.
node['apache2']['user'] # => testuser