In a new rail 3 app I want to replace prototype with jquery, but my initializer script:
module ActionView::Helpers::AssetTagHelper
remove_const :JAVASCRIPT_DEFAULT_SOURCES
JAVASCRIPT_DEFAULT_SOURCES = %w(jquery-1.4.1.min rails)
reset_javascript_include_default
end
won't work any more. I get:
constant ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES not defined
Any ideas?
inside your config/application.rb
config.action_view.javascript_expansions[:defaults] = ['jquery-1.4.2', 'rails']
Related
How can I work with a Trailblazer cell in the Rails console?
The concept helper doesn't work
irb(main):002:0> c = concept(Resource::Cell, l)
NoMethodError: undefined method `concept' for main:Object
Did you mean? concern
context
from (irb):2
concept() & cell() are Controller helpers, meaning they wouldn't work in console if the controller is not loaded. But you don't need them !
The easiest way to play with cell is just to invoke them like . you would with any other ruby object.
Cell
# concepts/song/cell/cell.rb
module Song::Cell
class Index < Trailblazer::Cell
def show
render
end
end
class Show < Trailblazer::Cell
def show
render
end
end
end
View
%h1
Song#show
%p
Find me in app/concepts/song/view/show.haml
Console
# Any of the following calls - they are all equivalent pretty much
# The spit html output of the cell
Song::Cell::Show.(Song.last).()
Song::Cell::Show.(Song.last).render
Song::Cell::Show.(Song.last).(:show)
I'm trying to implement free drawing in my windows 8 app but I keep getting this error:
"0x800a01bd - JavaScript runtime error: Object doesn't support this action
File: fabric.js, Line: 12857, Column: 7"
Adding images to the canvas etc. all works as it does in the demos but in VS when I hovered over "fabric" in this code, fabric.Shadow is not shown as an option in the list:
setShadow: function(options) {
return this.set('shadow', new fabric.Shadow(options));
},
Does anyone know why this isn't working for me? I created a build of the api from www.fabricjs.com and included all modules. I've copied the code from the free drawing demo (http://fabricjs.com/freedrawing/) but no joy. I also tried removing any reference to creating a shadow as I don't plan on using that functionality but it still crashes. Thank you
Thank you! It's working for me now. I did have to change the JavaScript provided by the demo to make it work though. Just as a reference to anyone who may want to use it with Windows 8 in future, the jquery code needs to be made more strict for it to update the selectors.
Provided code:
var $ = function(id){return document.getElementById(id)};
var drawingModeEl = $('drawing-mode'),
drawingOptionsEl = $('drawing-mode-options'),
drawingColorEl = $('drawing-color'),
drawingShadowColorEl = $('drawing-shadow-color'),
drawingLineWidthEl = $('drawing-line-width'),
drawingShadowWidth = $('drawing-shadow-width'),
drawingShadowOffset = $('drawing-shadow-offset'),
clearEl = $('clear-canvas');
I did away with the above and just used the standard jquery selector $('#drawing-mode') each time I needed it. Then the events were provided as:
drawingModeEl.onclick = function() {}
drawingColorEl.onchange = function() {}
so I changed the above to:
$('#drawing-mode').on('click', function () {});
$('#drawing-color').change(function (){});
Now everything works as it does in the demo. Love this API, thank you!
I'm creating a custom SimpleForm input. It utilizes a javascript modal popup to select values.
I can basically get it to work if I include the modal partial in the form view, but I would ideally like to have the custom input push the partial to the template.
However, I can't get it to work. I'm trying this, but it doesn't render the partial correctly.
class ProductCategoryImageSelectInput < SimpleForm::Inputs::CollectionSelectInput
def input
html = ''
html << 'Launch demo modal'
File.open("#{Rails.root}/app/views/product_categories/_browse_modal.html.erb", 'r') do |f|
html << f.read
end
end
end
Any thoughts?
EDIT
I'm apparently too new of a user to post screenshots, but here are links to the differences in functionality:
When I embed the modal code in the form, I get this, which is the desired functionality:
working
When I try to put the modal code in the custom input, I get this instead:
not working
You can also render partial from a custom input using the SimpleForm::FormBuilder instance which is assigned to an instance variable named #builder:
class ProductCategoryImageSelectInput < SimpleForm::Inputs::CollectionSelectInput
def input
#builder.template.render(partial: 'product_categories/browse_modal', locals: { foo: 'bar'})
end
end
Weirdly, it seems I've already answered it here.
Does this work for you?
ERB.new(f.read).result(binding)
PS: Updated with ERB instead of HAML.
How can I set Ext CSS to be just applied to Ext components?
This is what is mentioned in Ext documentation for scopeResetCSS:
scopeResetCSS : Boolean
True to scope the reset CSS to be just applied to Ext components.
Note that this wraps root containers with an additional element.
Also remember that when you turn on this option, you have to use ext-all-scoped
{ unless you use the bootstrap.js to load your javascript, in which case it will be
handled for you.
I have already set Ext.scopeResetCSS=true; & also Replaced the ext-all.css with ext-all-scoped.css, but that does not help.
Thanks to Donald Sipe for posting the solution for this in his blog.
You should create Ext object in the following manner before it is loaded by ext-debug.js script:
<script>
// Here we define Ext for the first time
Ext = {
buildSettings:{
"scopeResetCSS": true // Thanks, but I'll do my own scoping please
}
};
</script>
<script src="js/libs/ext/4.0.2a/ext-all-debug.js"></script>
By setting the scopeResetCSS value in buildSettings config object, you are telling ExtJS that you are going to handle CSS scoping all by yourself.
For example, to get a scoped version the gray theme:
install Compass
Then, on command line, move to the ExtJs Sass folder e.g. /extjs/resources/sass
duplicate the file ext-all-gray.scss
add the line $scope-reset-css: true; at the top of the file.
Then run: compass compile ext-all-gray-scoped.scss
This will create a file ext-all-gray-scoped.css in the CSS folder which you can now use.
I've trying to get properly work kcaptcha class from kcaptcha.ru in my own component. 'Cause class not build for Joomla natively I break my brain on the wall.
And at the beginning...
I've a url to image generated by this class like: http://.../index.php&task=captcha&format=raw
In main controller I've put method
function captcha() {
include(JPATH_COMPONENT.DS.'libraries'.DS.'captcha'.DS.'kcaptcha'.DS.'kcaptcha.php');
$session = &JSession::getInstance('default', array());
$captcha = new KCAPTCHA();
if ($session) {
$session->set('captcha_keystring', $captcha->getKeyString());
}
}
And I've see in browser
When I request an image from the class all working good but in my component I cannot set session variables.
Any ideas how to fix this problem?
And problem solved successfully.
For &format=raw in controller Joomla set default mime-type to text/html.
For healing this issue developer must reset mime/type via setting
$document = &JFactory::getDocument();
$document->setMimeEncoding('image/png');
mime/encoding off course depends on you needs.