undefined method `permit' for "<p>tinymce</p>":String - ruby-on-rails

Im trying to implement tinyme gem and I get this error:
undefined method `permit` for "<p>tiny mce</p>":String
This is the controller:
def note_params
params.require(:note).permit(:contact_id, :note)
end
The View:
<%= simple_form_for(#note) do |f| %>
<%= f.error_notification %>
<div class="form-group hidden-xs-up">
<label><i class="fa fa-address-book-o" aria-hidden="true"></i> Contact</label>
<%= f.select :contact_id, get_contact.collect{#contact.id},{}, class:"form-control" %>
</div>
<div class="form-group over-hide">
<label><i class="fa fa-file-text-o" aria-hidden="true"></i> Note</label>
<%= text_area_tag :note, "", :class => "form-control tinymce", :rows => 10, :cols => 60 %>
<%= f.button :submit, class: "btn btn-info mt-2 float-sm-right" %>
</div>
<% end %>
How should I fix this issue ?

Your form send the note directly as a root element and not nested in another note. This happens, because you use text_area_tag instead of the text_area form helper.
Just change:
<%= text_area_tag :note, "", :class => "form-control tinymce", :rows => 10, :cols => 60 %>
to
<%= f.text_area :note, :class => "form-control tinymce", :rows => 10, :cols => 60 %>

Related

Devise login form with form_inline in the navbar

I am trying to make a Devise login form as form_inline in my navbar.
At this point a have made it like this:
Link to picture of the navbar it look like a this point: http://postimg.org/image/i3ka5fsur/
it has the code:
<li><%= form_for(:user, :url => session_path(:user)) do |f| %>
<%= f.text_field :email, :placeholder => "Email" %>
<%= f.password_field :password, :placeholder => "Password" %>
<%= f.check_box :remember_me %><%= f.label :remember_me %>
<%= f.submit 'Login' %>
<% end %></li>
I'm just not quite happy with it's look at this point, I more want it like the form_inline:
Link to picture of the navbar I want it to look like: http://postimg.org/image/7590n949f/
the form_inline code is:
<form class="form-inline">
<input type="text" class="input-small" placeholder="Email">
<input type="password" class="input-small" placeholder="Password">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</form>
Hope some of you can help me, i'm new a programmering and don't have a lot of experience with programmering.
with twitter bootstrap3
<%= form_for(:user, :url => session_path(:user), html: { class: "navbar-form navbar-right form-inline" }) do |f| %>
<div class="form-group">
<%= f.text_field :email, :placeholder => "Email", class: "form-control" %>
</div>
<div class="form-group">
<%= f.password_field :password, :placeholder => "Password", class: "form-control" %>
</div>
<div class="checkbox">
<%= f.check_box :remember_me %><%= f.label :remember_me %>
</div>
<%= f.submit 'Login', class: "btn btn-default" %>
<% end %>
with twitter bootstrap2
<%= form_for(:user, :url => session_path(:user), html: { class: "navbar-form pull-right form-inline" }) do |f| %>
<%= f.text_field :email, :placeholder => "Email", class: "input-small" %>
<%= f.password_field :password, :placeholder => "Password", class: "input-small" %>
<label class="checkbox">
<%= f.check_box :remember_me %><%= f.label :remember_me %>
</label>
<%= f.submit 'Login', class: "btn" %>
<% end %>
You should include the css that describes form_inline class and input-small class e.t.c
Then in your code you should assign classes to your elements like below
<li><%= form_for(:user, :url => session_path(:user)), :class => "form-inline" do |f| %>
<%= f.text_field :email, :placeholder => "Email", :class => "input-small" %>
<%= f.password_field :password, :placeholder => "Password", :class => "input-small" %>
<%= f.check_box :remember_me, :class => "checkbox" %><%= f.label :remember_me, :class => "checkbox" %>
<%= f.submit 'Login', :class => "btn" %>
<% end %></li>

Rails 4 - How to populate remote content in a form?

Here is what I have
I have a method like this in my bookmarks_controller.rb
def fetch
#result = LinkThumbnailer.generate(params[:url])
end
I have the following form fields to create new bookmarks
url
title
description
thumbnail
tags
So my new.html.erb looks like this
<%= form_for(#bookmark, :html => {class: "panel-body"}) do |f| %>
<% if #bookmark.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#bookmark.errors.count, "error") %> prohibited this bookmark from being saved:</h2>
<ul>
<% #bookmark.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="block">
<%= f.label :url, :class => 'control-label' %>
<%= f.text_field :url, :class => 'form-control', :placeholder => 'URL' %>
</div>
<div class="block">
<%= f.label :title, :class => 'control-label' %>
<%= f.text_field :title, :class => 'form-control', :placeholder => 'Title' %>
</div>
<div class="block">
<%= f.label :description, :class => 'control-label' %>
<%= f.text_area :description, rows: 6, :class => 'form-control', :placeholder => 'Description' %>
</div>
<div class="block">
<%= f.label :thumbnail, :class => 'control-label' %>
<%= f.text_field :thumbnail, :class => 'form-control', :placeholder => 'Thumbnail url' %>
</div>
<div class="block">
<%= f.label :tag_list, :class => 'control-label' %>
<%= f.text_field :tag_list, :class => 'form-control', :placeholder => 'Tags (separated by commas)' %>
</div>
<div class="actions">
<%= f.submit :class => "btn btn-info" %>
</div>
<% end %>
I would like to have a button called Fetch right next to url field.
When user click Fetch button, I would like to populate the form fields using ajax.
I viewed rails documentation. It says to add remote: true attribute to the form.
But I wanna use ajax function only when the user click fetch button.
Can someone help me with this?
Thankyou
You can generate an object using the LinkThumbnailer gem and than convert it to json
with this action:
def fetch
#result = LinkThumbnailer.generate(params['given_url'])
respond_to do |format|
format.json do
result.to_json
end
end
end
And in your view you could use the Jquery getJSON method to access the #fetch action and pass the given url as a parameter:
<script type="text/javascript">
require(['jquery'], function($) {
$('.fetch-button-class').change(function() {
var given_url = $('.url-class').val();
$.getJSON('<%= fetch_action_url %>', {'given_url': given_url }, function(obj) {
$('.title-class').val(object.title);
$('.description-class').val(object.description);
});
});
});
</script>

adding html id to form_tag rails 4

I currently have this sign in form in a rails 4 app in which I use the form_tag helper. I'm need to add an id. I tried using <%= form_tag( :html => {:id => 'login_form'} ) do %> but I get an error.
<%= form_tag do %>
<div class="form-group">
<%= label_tag :name, 'Username:', class: "control-label" %>
<div class="controls">
<%= text_field_tag :name, params[:name], class: "form-control", size: "30", tabindex: "1" %>
</div>
</div>
<div class="form-group">
<%= label_tag :password, 'Password:' %>
<div class="controls">
<%= password_field_tag :password, params[:password], class: "form-control", size: "30", tabindex: "2" %>
</div>
</div>
<div class="form-group">
<div class="controls">
<%= submit_tag "Sign in", class:"btn btn-large", tabindex: "2" %>
</div>
</div>
<% end %>
<%= form_tag('/login', id: "login-form") do %>

ruby: updating file upload markup - cannot work it out

i have only been introduced to ruby this week on a new clients project and been updating some file inputs however i have got to one that is different and cannot work out how to write into the new markup i need. can anyone lend a hand?
currently it is:
<div class="input inline">
<% if host_group %>
<%= label :upload_csv_of_hosts, t(:upload_csv_of_hosts), t(:upload_csv_of_hosts) %>
<% else %>
<%= label :upload_csv_of_participants, t(:upload_csv_of_participants), t(:upload_csv_of_participants) %>
<% end %>
<div class="markup">
<%= file_field_tag "csv" %>
<%=show_required %>
<%= host_group ? show_info('group/hosts_csv') : show_info('group/participants_csv') %>
</div>
</div>
which is just using file_field_tag "csv" but i need to build that into this markup like i have for the others i converted, the others i converted was done in a different way that the one above so unsure what that one does and how to implement it into the required markup below.
<div class="input inline">
<%= f.label :filename, t(:uploaded_data), :class => "double" %>
<div class="markup">
<%= f.text_field :filename, {:size => 20, :readonly => true, :class => "file_input_textbox", :value => "No File Selected"} %>
<div class="file_input_div">
<%= f.button :browse, :class => "button button-red file_input_button" %>
<%= f.file_field :filename, {:size => 20, :class => "file_input_hidden"} %>
</div>
</div>
<%=show_required%>
<%=show_info('document/uploaded_data') %>
</div>
i have tried this....
<div class="input inline">
<% if host_group %>
<%= label :upload_csv_of_hosts, t(:upload_csv_of_hosts), t(:upload_csv_of_hosts) %>
<% else %>
<%= label :upload_csv_of_participants, t(:upload_csv_of_participants), t(:upload_csv_of_participants) %>
<% end %>
<div class="markup">
<%= f.text_field :csv, {:size => 20, :readonly => true, :class => "file_input_textbox", :value => "No File Selected"} %>
<div class="file_input_div">
<%= f.button :browse, :class => "button button-red file_input_button" %>
<%= f.file_field :csv, {:size => 20, :class => "file_input_hidden"} %>
</div>
</div>
<%=show_required %>
<%= host_group ? show_info('group/hosts_csv') : show_info('group/participants_csv') %>
</div>
but i get the following error:
undefined local variable or method `f' for #<#<Class:0x00000007672a58>:0x00000007631a30>
its 1:25am and really want to crack this, so very thankful to any helpers!
Thanks
If you are getting this error:
undefined local variable or method `f' for #<#:0x00000007631a30>
When you run this line:
<%= f.text_field :csv, {:size => 20, :readonly => true, :class => "file_input_textbox", :value => "No File Selected"} %>
And you start your form like this:
<%= form_for(:group, :url => url, :html => { :snipped => true }) do %>
Then you need this instead:
<%= form_for(:group, :url => url, :html => { :snipped => true }) do |f| %>
You can't use the form builder object if your form_for block doesn't yield it!
Also do you see how much of relevant bits of code here were not in your original version of the question? :)

How to hide a form field and still have it submit all the fields?

I've got this rails form partial:
<%= form_for #ptab, :remote => true, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :name, :class => 'text_field', :placeholder => 'Enter a name...' %>
</div>
</div>
<div class="control-group">
<%= f.label :address, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :address, :class => 'text_field', :placeholder => 'Paste a link...' %>
</div>
</div>
<div class="control-group">
<%= f.label :sequence, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :sequence, :class => 'number_field', :placeholder => 'Enter an order number...' %>
</div>
</div>
<div class="control-group">
<%= f.label :gtab_id, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :gtab_id, :class => 'number_field' %>
</div>
</div>
<div class="modal-footer">
<%= f.submit nil, :class => 'btn btn-primary' %>
<!-- <%= link_to t('.cancel', :default => t("helpers.links.cancel")), ptabs_path, :class => 'btn' %> --> <!-- this was the original cancel button -->
<a data-dismiss="modal" class="btn" href="#">Close</a>
</div>
<% end %>
I would like to turn the field in the last .control-group into a hidden field, but I still want it to be submitted to the controller.
What should I change this to :
<div class="control-group">
<%= f.label :gtab_id, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :gtab_id, :class => 'number_field' %>
</div>
</div>
In order for it to not show in the rendered form but still be submitted with the form?
Use a hidden_field ? Or did I miss something ?
<%= f.hidden_field :gtab_id %>
And of course remove the divs around it as well as the label. hidden_field are submitted as regular fields, no worries

Resources