set default value for a textarea of rails fckeditor plugin - ruby-on-rails

I have a textarea in my view page and I am using rails fckeditor plugin for converting it into WYSIWYG editor. I need to set the default value for the textarea. How it is possible.I have written like this.. Please help
<%= fckeditor_textarea :reminder, :body,:lang => I18n.locale,:langdir => (rtl? ? 'rtl' : 'ltr') %>

Related

Datalist input type with formtastic is not working

I am using active admin in my application with rails version 3.2.22.2. I am using formtastic version ~> 2.0. I tried to have a text field with autocomplete option, similar to HTML datalist. When I included
<%= f.input :fav_book,:as => :datalist,:collection => books.pluck(:product) %>
it throws error as Unable to find input class for datalist. Is there any way to achieve the same

bootstrap wysihtml5 is not working in IE9

In rails 3.2.9, i am using bootstrap's wysihtml5 editor to one textarea field but in IE9 i am not getting that field's(textarea) value. I am loading a form via ajax to preview this text field's details before saving it. In IE-10 it is working fine.
In application.js
//= require bootstrap-wysihtml5
In application.css
*= require bootstrap-wysihtml5
While serializing the form i am not getting text field's value
form_data = jQuery("#form_id").serialize();
jQuery.ajax({type :'POST', url : '/user/preview.js?', data : form_data});
In views,
<%= f.input :description, :as=>:text, :label =>false, :required => false, :placeholder=>"Description", :input_html=>{:rows=>"10", :class=>"texteditor", :style=>"width: 520px;"} %>
In script,
function loadTextEditor(){
$('.texteditor').wysihtml5();
}
window.onload = loadTextEditor();
How do i get texteditor's value before saving it via ajax. Please help me to solve this issue.
Did you try to look the error on inspect element > console?
Always use the editor object to get the value of the textarea:
$('.texteditor').data("wysihtml5").editor.getValue();

Rails : simple_form : Getting an empty string from checkbox collection

I have the following code in my views
<%= f.input :role_names, as: :check_boxes, collection: #program.role_names %>
And whenever I submit the form I am getting values something like ["admin, "moderator", ""] but I was expecting something like ["admin, "moderator"] , why is this?
Moreover I made a inspect element, and there was a <input name="user[role_names][]" type="hidden" value=""> tag after the last check box, within the same control-group. I suppose this is getting added at the last in the params[:user][:recipient_role_names].
How should I handle this? I know I can do a reject(&:blank?) but is there a cleaner way on params[:user][:recipient_role_names]?
I also want to know why the input element is getting added? Is it a bug in simple form or I have done something wrong?
Other info:
simple_form gem version: 2.0.4
rails version: 3.2.8
It's a Rails' feature. You'll be able disable it in Rails 4. You can read more about this on simple form issue #603 and Rails issue #5402
Just add include_hidden: false to your input params:
<%= f.input :role_names,
as: :check_boxes,
collection: #program.role_names,
include_hidden: false
%>
And the empty string value won't be sent in the array.
Obs: I've just added the simple_form input code here for quick reference, as it was Vasily's answer that pointed me in the right direction. Thank you

Twitter Bootstrap Typeahead text field name attrib messes with autocomplete

I am using the typeahead js extension from twitter bootstrap for an autocomplete field. I have a subtle problem with that. I have a text field like :
<%= text_field_tag :search, params[:search], :data => { :provide => 'typeahead', :source => ...} %>
The problem is that i have to specify name='search' (with :search), in order to be able to grab the text input search value. However, if i do so, the browser automatically creates an autocomplete history of the entries i have already tried in my text field.
If i remove :search and replace with '', the browser cannot 'save' the history, because there is no name attribute on the text field. However, this way, i cannot get the inputted value myself.
How can i work around this ?
When I use autocomplete from jquery-ui, it sets the attribute autocomplete="off" in the input tag, so you might try including the option :autocomplete=>"off". The field doesn't show any inputs from the history, just what was passed in to autocomplete.
If that doesn't work, just try jquery-ui's autocomplete instead. It definitely works.

Empty attribute with Ruby HAML

I'm implementing Schema microformats on a Ruby project using HAML and can't figure out how to set an empty attribute on a tag. I tried nil and false, but they simply do not shown.
Example: <div itemscope>
I'm tring to set an empty itemscope attribute.
Code added from comment by #StrangeElement:
My code:
.agency.premium{:itemscope => true, :itemtype => 'schema.org/ProfessionalService';}
:itemscope => true seems to be the recommended approach from HAML's documentation. I get the same result as I would get with :itemscope => '', a XHTML-valid attribute with an empty value (i.e. <div itemscope="">).
Probably fine, but I'd rather have it empty as is documented in the Schema doc.
Using something like
%div{:itemscope => true}
is the correct way to specify this in your Haml file.
How this is rendered depends on how you set Haml's format option. The default in Haml 3.1 is xhtml, and with that it will render as itemprop='itemprop', which is valid xhtml. To render with minimized attributes (like <div itemscope>) you need to set the format to html4 or html5. (In Rails 3 the default is html5, and in Haml 4.0 the default is html5).
How to set the Haml options depends on how you are using it, see the options section in the docs.
For example, using Haml directly in Ruby, this:
engine = Haml::Engine.new '%div{:itemscope => true}'
puts engine.render
produces the default xhtml with full attributes:
<div itemscope='itemscope'></div>
But this:
engine = Haml::Engine.new '%div{:itemscope => true}', :format => :html5
puts engine.render
produces the desired result with minimized attributes:
<div itemscope></div>
If someone is interested in how to put more words in that way, he may use "foo bar" => true:
%option{ "disabled selected value" => true } Choose an option
results is:
<option disabled="" selected="" value="">Choose an option</option>
and works as expected.
The accepted answer works, but it produces an HTML attribute with value.
If you want the attribute only to be output on HTML, without value, you can use the HTML-style attributes syntax of HAML:
%div(itemscope)

Resources