Rails ActiveAdmin with carrierwave - ruby-on-rails

I am using ActiveAdmin with rails 4 and it is working fine. When I add an item, I am taken to the index page listing the new item/items and the filters on the right side. Also, there are the email and logout links at the top right.
My issue is when I add an item with an image the filters, email and logout links disappear.
If I delete the item with the image they appear again. I can add /new to the url and it still takes me to the form but I am trying to figure out why adding a picture removes the links.
here is my form:
form(:html => { :multipart => true }) do |f|
f.inputs "Size" do
f.input :title
f.input :description
f.input :price
f.input :image, :as => :file
f.input :developer_days
f.input :designer_days
f.input :name
end
f.actions
end
I just can't figure out why this happens.

Related

Selected drop down menu in simple_form when f.association is present in the view

Can you please tell me if there is a way using simple_form with Rails, when you have "f.associations" present in a view, to disable the selected drop down menu in the form but still use the prefilled value of the field?
I have tried with option ":disabled => true" but it disables the whole text field and a I need a value to be present here. When I submit the form I receive an error that a value should be present.
I have tried with option ":as => :hidden", the input value does not appear, but when I submit the form I receive an error that a value should be present.
I have tried with option ":readonly => true", but drop down menu still appears. It appears grayed out but can still be selected.
Thank you,
Silviu
Use input hidden with same variable and value for f.assocation disabled, when submit form, the needing value will be sended at once time.
Sample code illustrate the case, note line f.association :company get the value company_id but not send, so the f.input :company_id will replace, and works!
Welcome to project railstrace !
<p>Simple Form content: </p>
<%= simple_form_for #user, url: save_path, :method => :post do |f| %>
<%= f.input :email %>
<%= f.association :company, disabled: true %>
<%= f.input :company_id, :as => :hidden, :input_html => {:value => #user.company_id} %>
<%= f.association :roles %>
<%= f.button :submit %>
<% end %>

Rails unable to change label in formtastic

Hi I'm new to rails and formtastic.
I've built a working solution for multiple file uploads using paperclip.
In my form, when I try and change the label of the upload file it still displays 'image' even when changing to:
<%= f.inputs :image, :label => false, :for => :attachments, :as => :file %>
or
<%= f.inputs :image, :label => "This label will not display", :for => :attachments, :as => :file %>
really silly problem but any help would be appreciated
thanks
f.inputs does not support label attribute, you should use f.input if you want hide label. Or you can bypass this and hide label via css. Something like this.
label[for=here_go_your_for_value] {
display: none;
}

CKEditor on custom page in activeadmin

i got the following issue:
I want to add a form on a custom page (no model) to design an email for mailjet. I already got a custom page and a form with an CKEditor input and an input for the subject. But the subject field isn't shown on the page.
This is my code:
ActiveAdmin.register_page "Mail", namespace: :lku do
def send_mail
end
content do
panel 'Write mail' do
semantic_form_for :mail, :url => "lku/send_mail", method: :post do |f|
f.inputs do
f.input :subject, :input_html => { :name => 'subject' }
end
f.inputs do
f.input :text, as: :ckeditor, :input_html => { :name => 'text' }
end
end
end
end
end
And this is the result:
When I add
f.actions
it looks like this
can someone help me please?
I was able to reproduce the problem without having ckeditor. Only the last element of form would display.
I don't know exactly what's going on, but it has something to do with how Arbre renders the content you generate inside the content block.
My solution is this
Transform the form content into .erb and move the form under views/lku/mail/_mailform.html.erb
<%= semantic_form_for :mail do |f| %>
<%= f.inputs do %>
<%= f.input :subject %>
<%= f.input :text %>
<% end %>
<%= f.actions %>
<% end %>
Include the form in the page
content do
panel 'Write mail' do
render partial: 'mailform'
end
end
See if you can still mount the editor by using regular Rails form helpers - https://github.com/galetahub/ckeditor#form-helpers

ROR - ActiveAdmin how to break lines?

I've been using ActiveAdmin to create new posts for my news app, the problem is that even though I'm using the type "text' for my body property I don't know how to break lines when writing a new post.
That's my code:
ActiveAdmin.register Post do
permit_params :title, :body, :description, :remote_image_thumb_url, :remote_image_banner_url, :category_id
form do |f|
f.inputs "Post Details", :multipart => true do
f.collection_select :category_id, Category.all, :id, :name
f.input :title
f.input :body
f.input :description
f.input :remote_image_thumb_url
f.input :remote_image_banner_url
end
f.actions
end
end
I've been googling for a while but didn't fidn any solutions yet. Any ideas?
Rails saves the new lines when you hit the carriage return. However to render it is a different thing because it is naturally escaped.
You have a few options:
Use the default simple_format in rails.
Use a markdown renderer like Redcarpet to do that + alot more functionality.

Add a custom action button in active_admin input form

Iam working on active_admin form. my requirement is to add a button beside a input box to create new project
How to add a action item inside a form ?
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Details" do
f.input :task
f.input :project
f.input :members, :input_html => { :class => "chosen-input" }, :label => 'Assigned To'
f.actions
end
end
i want to add a new project button beside input field project
Though it is a very old question, stil i was also looking for the answer, This is how to do it:
just add it after f.input :project:
f.button "New Project", formaction: "new_entry", class: "some_class"
Then using member_action:
member_action :new_entry, method: :patch do
end
inputs 'Details' do
li do
label "Project"
span do
"here is your project input field"
end
span do
"here is your button"
end
end
end

Resources