ckeditor doesnt show anything in the edit form and the dbms doesnt even load in the editor - ckeditor

I tried the ckeditor and it works fine when adding or making a new post but the problem is when I try and edit the post.
it doesn't load properly and it doesnt show anything like the code , or even a spec, it just shows the pre default ckeditor list and it doesn't even show any data coming from the database.
any help would really be great, and info would be awesome.
I have made it into a form and then rendering it so that I can just call the function like so.
This is the _form
<p>
<%= f.label :text %><br>
<%= f.cktext_area :text, :value => 'Default value', :id => 'sometext' %>
</p>
Now this is in my edit
<%= render 'form' %>
I tried adding the raw into it like so
<%= raw render 'form' %>
or even into the _form but it doesn't seem to show properly
after tinkering and trying the usual thing the codes show it.
<p>
<%= f.label :text %><br>
<%= f.text_field :text %>
</p>
when I try it and add this now it shows here , but the ckeditor doesn't show properly.

Just give this:
<p>
<%= f.label :text %><br>
<%= f.cktext_area :text %>
</p>
I hope you are calling this partial inside a form_for.

Update the answer,
Just remove
:value => 'Default value',

Related

Ruby submit_tag button not doing anything

I want to create a form_tag in my index view to accept an id which gets passed to my populateOne method. The view has been updated properly, both the number_field_tag in the form and the submit_tag are there, but when I press the button on my server, nothing happens!
Here is my view:
<%= form_tag('/affinities/populateOne/:id', method: :put) %>
<%= number_field_tag(1) %>
<%= submit_tag 'Populate One' %><br>
Here are my routes: EDIT:
put 'affinities/populateOne/:id' => 'affinities#populateOne', :as => 'populateOne_affinity'
My populateOne method is long, so here is the relevant part:
def populateOne
userA = User.find(params[:id])
...
end
What could be the problem? All help is very much appreciated! Thanks!!!
Your form_tag is posting data to the url using put method. And your route has get method. Fix it with put:
put 'affinities/populateOne/:id' => 'affinities#populateOne', :as => 'populateOne_affinity'
View:
<%= form_tag('/affinities/populateOne/:id', method: :put) %>
Route:
get 'affinities/populateOne/:id' => 'affinities#populateOne', :as => 'populateOne_affinity'
Your form submit method and your route don't match. Your form is putting, and doing what you want it to, but the route is trying to get something that isn't there. Change the route's get to put and it should work as intended.
In my index view, I forgot to put do ... end for the form_tag:
<%= form_tag('/affinities/populateOne/:id', method: :put) do %>
<%= number_field_tag(1) %>
<%= submit_tag 'Populate One' %>
<% end %><br>

How to Accept ONLY Two Keys Before User :Submit?

I want people to be able to challenge their habits. If they miss a day they may put "/" if they miss two days in a row they must put "X". Three X's means they failed the challenge.
How can I force the User to only be able to submit X's and /'s as valid keys in the :missed input field?
_form excerpt
<%= simple_form_for(#habit) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :missed %>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Github: https://github.com/RallyWithGalli/ruletoday
Thanks in advance for your help. You rock!
You can use a select tag to limit users' options like this
<%= select_tag(:missed , options_for_select([['/', '/'], ['X', 'X']])) %>

Formtastic Creating a form without users

I'm creating a web application with formtastic. I installed the gem and wrote my code like this:
<%= semantic_form_for #index do |form| %>
<%= form.inputs do %>
<%= form.input :name %>
<%= form.input :born_on, :start_year => 1997 %>
<%= form.input :description, :as => :text %>
<%= form.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %>
<% end %>
<%= form.actions do %>
<%= form.action :submit, :as => :button %>
<% end %>
<% end %>
I want the form to appear on the index page which is why I have #index. For some reason I can't do #index. How would I reference the top line so that it renders a form on the index page? Currently my index page has nothing in it, but it is defined in the controller
form_for helper expects some object that responds to fields You refer inside Your form. Here is an example of using semantic_form_for with plain Ruby object: http://affy.blogspot.com/2010/02/using-formtasic-without-activerecord.html.
Also the object You specify for form doesn't effect which page is being rendered. Are You sure You are not mixing up something? Maybe if You share a bit more of Your controller code we might help You better.

prevent double click with disable_form, ruby on rails

I'm trying to prevent a form from being "double posted", when the user either clicks twice or hits submit twice.
I've seen a couple posts on this, but they haven't hit this issue per se. I can't seem to get the below to stop double-posts, and I'm getting the feeling it's related to the remote => true (using ajax to show the content on the page).
Below is my form:
<%= form_for([#posts, #comment], :remote => true) do |f| %>
<%= f.text_field :comment %>
<%= f.submit "Submit", class: "btn btn-large btn-primary", :style => 'display: none;', :disable_with => '' %>
<% end %>
Any recommendations would be great. Thank you!
Use the disable_with option
<%= submit_tag :submit, :id => 'submit_button', :value => "Create!", disable_with: "Creating..." %>
The other answer didn't work for me — I believe it was from the Rails 2 era. According to the docs, the disable_with attribute should be added within a data attribute, like so:
<%= submit_tag "Complete sale", data: { disable_with: "Please wait..." } %>

Paperclip multiple upload & save extra field

Im stuck uploading multiple photos to my model when adding an extra field to the photo model. In the code i hard code "1" value to the hidden_field, but i will change it eventually. The paperclip gem raises a rollback and won't insert the photos in the post. If i erase the "hidden_field" line it will success. Any ideas on how to add extra field to the upload in the view?
<%= form_for #campaign_point_of_sale, :html => {:multipart => true }, :url => "/pos/#{#point_of_sale.id}/post/#{#campaign.id}", :method => :post do |f| %>
<%= f.hidden_field :id %>
<label>Add photo <br />
<%= f.fields_for :campaign_result_point_of_sale_photos do |builder| %>
<% if builder.object.new_record? %>
<%= builder.hidden_field :is_mount_photo, :value => "1" %>
<%= builder.file_field :photo %>
<% end %>
<% end %>
<%= f.submit(:value => "Save") %>
Got it!
Just needed to delete the whole builder with both hidden_field and file_field, so the server would not try to insert a picture without an image file (just with a hidden_field value)
This can be achivied by surrounding both inputs with a div and deleting it (with jquery) at form submit if the file_field value was empty. Pretty cheap but works!

Resources