Froala Rails wraps around textarea - ruby-on-rails

I am trying to implement froala editor in my rails application but the editor wraps around the textarea and even the label is editable
Here is my form
<%= simple_form_for([:admin, #article], class: 'form') do |f| %>
<%= f.input :title, label: 'Title' %>
<%= f.input :text, id: 'text', as: :textarea %>
<%= f.association :category, label: 'Category' %>
<%= f.association :tags, label: 'Tags' %>
<%= f.input :photo, as: :file %>
<%= f.submit #article.new_record? ? 'Post Article' : 'Update Article', class: 'btn btn-success btn-block btn-medium' %>
and this is the result

Change from f.input to f.input_field

Related

How do I add an autocomplete="street-address" attribute to rails form_for

I'm trying to add Mapbox autofill to my address bar on rails, for mapbox autofill to work I need to have autocomplete="street-address in an input field.
I'm using simple_form_form and I can't figure out how to add autocomplete attribute. Here is my form:
<%= simple_form_for #lock do |f| %>
<div class="form_wrapper">
<div class="form_div">
<%= f.input :name %>
<%= f.input :description %>
<mapbox-address-autofill>
<%= f.input :address, :autocomplete => "street-address" %>
</mapbox-address-autofill>
<%= f.input :photo, as: :file, label: "Link to picture" %>
<%= f.input :special_content %>
<%= f.button :submit, :class => "btn btn-primary" %>
<% end %>
any ideas on how to make the autocomplete attribute work?
Use input_html and pass the additional options like class etc.
<%= f.input :address, input_html: { :autocomplete => "street-address"} %>

Rails : Drop down in simple_form doesn't retain value when directed to edit path

I have a drop down selector in a form and even after saving an object, when I go to my edit page, the drop down reverts to the first item. If submit is clicked, the value changes to the first item in the list.
In this case the drop down contains a list of states. Every time I go to the edit page, Alabama is selected and if I don't manually change the value back to what it initially was, the state becomes Alabama.
<%= simple_form_for #event, url: coin_event_path(#coin.id) do |f| %>
<%= f.input :content, :label => "Event Description", class: 'form-control' %>
<%= f.input :link, :label => "Link to Event", class: 'form-control' %>
<%= f.input :date, order: [:month, :day, :year], class: 'form-control' %>
<%= f.input :time, as: :time, html5: true, class: 'form-control' %>
<%= f.input :city, class: 'form-control' %>
<%= f.select :state, options_for_select(us_states),{}, class: 'form-control' %>
<%= f.input :description, :label => "Event Description", class: 'form-control' %>
<% if can? :destroy, Event %>
<%= f.select :accepted, [['Accepted', true], ['Not Accepted', false]] %>
<% end %>
<%= f.button :submit, 'Submit' %>
<%= link_to "Back", coin_path(#coin.id), class: "btn btn-default" %>
How do I change this so it stays on the state that it's supposed to?
You can using selected, like:
options_for_select(us_states, selected: "set_current_value")
More usage examples - options_for_select() docs.

Simple_form and association

I have this form:
<%= simple_form_for #request, html: {class: 'form-horizontal' } do |f| %>
<%= f.input :initiator, label: 'initiator' %>
<%= f.association :department, collection: Department.all, value_method: :id, label: 'Назначить на отдел' %>
<%= f.association :user, collection: User.all, label_method: :email, label: 'Ответственный' %>
<%= f.input :comment, label: 'comment' %>
<%= f.input :sla, label: 'SLA' %>
<%= f.button :submit, label: 'Создать', class: "btn btn-primary" %>
<% end %>
How can I make the association:
If I choose "Department 1" from: Department, the choice of the :user will only users who belong to this department. (When you open the drop-down list were only people from the Department 1, not Users.all) What parameters I have to pass the rails?
I doubt if it is possible only using simple_form
Try http://www.petermac.com/rails-3-jquery-and-multi-select-dependencies/
I would advice against loading all users in DOM, use an ajax action to filter users if they are many

DRY Rails Forms - Form Partials

I'm having problems with repetetive Rails form codes. When I put them in a partial they are throwing NoMethodError and I couldn't figure it out how to make them DRYer.
admin/exam_centers/edit.html.erb =>
<%= simple_form_for(#exam_center, url: admin_exam_center_path(#exam_center)) do |f| %>
<%= f.input :city_id, collection:City.all, label: 'Şehir Seçiniz', label_method: :name %>
<%= f.input :address, label: 'Adres' %>
<%= f.input :building, label: 'Bina' %>
<%= f.button :submit, "Kaydet", :class => "btn btn-info" %>
<% end %>
Notice: admin_exam_center_path(#exam_center)
admin/exam_centers/new.html.erb =>
<%= simple_form_for(#exam_center, url: admin_exam_centers_path(#exam_center)) do |f| %>
<%= f.input :city_id, collection:City.all, label: 'Şehir Seçiniz', label_method: :name %>
<%= f.input :address, label: 'Adres' %>
<%= f.input :building, label: 'Bina' %>
<%= f.button :submit, "Kaydet", :class => "btn btn-info" %>
<% end %>
Notice: admin_exam_centers_path(#exam_center)
They are working perfect like this. But when I put them in a partial as you can see below, the new.html.erb page is throwing "undefined method exam_centers_path" error and the edit.html.erb page is throwing "undefined method exam_center_path" error. How can I make these form DRYer?
_form.html.erb =>
<%= simple_form_for(#exam_center) do |f| %>
<%= f.input :city_id, collection:City.all, label: 'Şehir Seçiniz', label_method: :name %>
<%= f.input :address, label: 'Adres' %>
<%= f.input :building, label: 'Bina' %>
<%= f.button :submit, "Kaydet", :class => "btn btn-info" %>
<% end %>
edit.html.erb =>
<%= render 'admin/exam_centers/form' %>
new.html.erb =>
<%= render 'admin/exam_centers/form' %>
By the way, the routes file =>
namespace :admin do
resources :exam_centers, except: :show
resources :exam_languages, except: :show
end
It looks like you just need to use a polymorphic url builder to specify the :admin piece of your route. Try specifying the form helper like this:
<%= simple_form_for([:admin, #exam_center]) do |f| %>
This will allow Rails to tack on the admin_ piece of the named route before generating the rest.
You only put common part in partials so you can do something like this:
new.html.erb
<%= simple_form_for(#exam_center, url: admin_exam_centers_path(#exam_center)) do |f| %>
<%= render partial: "form", locals: {:f => f} %>
<% end %>
edit.html.erb
<%= simple_form_for(#exam_center, url: admin_exam_center_path(#exam_center)) do |f| %>
<%= render partial: "form", locals: {f: "f"} %>
<% end %>
_form.html.erb
<%= f.input :city_id, collection:City.all, label: 'Şehir Seçiniz', label_method: :name %>
<%= f.input :address, label: 'Adres' %>
<%= f.input :building, label: 'Bina' %>
<%= f.button :submit, "Kaydet", :class => "btn btn-info" %>

Rails: Issue with simple_form

I've built a simple_form form in my rails app and things went just fine:
<%= simple_form_for([#folha, #servico], html: {class: 'well form-horizontal'}) do |f| %>
<%= f.association :pessoa, label: 'Funcionário' %>
<%= f.input :funcao, label: 'Função',collection: #funcoes %>
<%= f.input :modulos, label: 'Módulos', input_html: {class: 'span4'} %>
<%= f.input :valor, label: 'Valor por hora', as: :string ,input_html: {class: 'span1'} %>
<%= f.input :horas, as: :string, input_html: {class: 'span1'} %>
<%= f.button :submit, 'Incluir', class: 'btn btn-primary' %>
<% end %>
To change the order list on the dropdown for the f.association i've overwritten the default .all method in Pessoa.rb:
def self.all
order :nome
end
Then i got this error when trying to render my view:
wrong number of arguments (1 for 0)
Extracted source (around line #5):
2: <h1>Preencher Pagamentos - Folha <%= "#{#folha.mes}/#{#folha.ano}" %> <small> <%= #folha.obs %> </small> </h1>
3: </div>
4: <%= simple_form_for([#folha, #servico], html: {class: 'well form-horizontal'}) do |f| %>
5: <%= f.association :pessoa, label: 'Funcionário' %>
6: <%= f.input :funcao, label: 'Função',collection: #funcoes %>
7: <%= f.input :modulos, label: 'Módulos', input_html: {class: 'span4'} %>
I think its better find a way to order the list in the view. But im very curious about what
is going on...
You should not override those kind of methods in first place.
Here is how to do it with simple_form
f.association : pessoa, :collection => Pessoa.order(:nome).all
https://github.com/plataformatec/simple_form/#associations
You can use default_scope as described here.
Use this macro in your model to set a default scope for all operations on the model.
In your case default_scope order(:nome).

Resources