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
Related
I have been trying to create a form on a page, with an instance variable #next, but it doesn't seem to work. When I remove the part which includes the form, the page opens up, clearly depicting that the paths have been correctly mentioned in routes.rb. To be clear,i haev added the following method in the controller file
def new
#next=Self.new
end
The part where form is created.
<%= form_for(#next) do |a| %>
<%= a.text_field_tag :name %>
<%= a.text_field_tag :prof %>
<%= a.text_field_tag :pic, :placeholder => 'Enter address' %>
i m using Rails 4.0.2
routes.rb
get '/worms' => 'worms#index'
get '/worms/new' => 'worms#new'
post '/worms' => 'worms#create'
get '/worms/:id' => 'worms#show'
Please help.
Your form should be look like this as below...
Self means what ?, You should write the name of your model here.
And If you need full CRUD operation on the same then write the below line for the routes...
resources :your-model-name-in-plural
<%= form_for #next do |a| %>
<%= a.text_field :name %>
<%= a.text_field :prof %>
<%= a.text_field :pic, :placeholder => 'Enter address' %>
Im trying to design a shopping cart. i.e a customer shopping online adds a product to their trolley.
I want to go straight to create action from my new action without going to new.html.erb with pre-set values in my params
Here is what I have so far:
#trolley_id += 1
redirect_to :controller => 'trolleys', :action => 'create', :id => #trolley_id, :something => 'else', method: :post
This redirects me to my index action
To do this with javascript templates, it would look like this:
view
= form_form Trolley.new, remote: true do
-# form goes here
The remote true will submit it as javascript, which will try to render a javascript template.
Your create action can either render :create or let Rails render your template automatically. Since it came in as a javascript request, Rails will render the template with format js.
trolleys/create.js.erb
var html = "<%= j render 'trolley_row', trolley: #trolley %>
$('table.trolleys body').append(html);
I managed to resolve my problem. I created a form in my Product_controller#show that will go straight to my Trolley_controller#create and create an entry in my Trolleys table
<%= simple_form_for [#product, #trolley] do |f| %>
<%= f.input :quantity, collection: 1..12, prompt: "select quantity" %>
<%= f.input :product_id, :as => :hidden %>
<%= f.input :user_id, :as => :hidden %>
<%= f.button :submit, "Add to Basket" %>
<% end %>
If I have a form taking a collection of names, a date, and another boolean via virtual attributes how can I submit them to a new page and action. That has nothing to do with CRUD. It will simply do some processing then spit out the values on a new page.
personsSelection.erb
<%= render :partial => 'myForm' %>
_myForm.html
<%= simple_form_for(#person) do |f| %>
<%= f.input :names, :collection => People.all, as => :check_boxes %>
<%= f.input :DateTime %>
<%= f.check_box :paid %>
<%= f.submit %>
person_controller.erb
def personReport
#Some Random Processing
end
personReport.html.erb
#Display the personReport processing data
Again, I'm trying to submit the form to process via personReport action then display to a new page called personReport.html.erb
In your routes
match "/person/personreport" => "person#personReport", :as => personreport
In your form
<%= simple_form_for(#person, :url => personreport_path) do |f| %>
This will send the data to your personReport action where you can process the data then by default that action will render personReport.html.erb
I've got two gems that i use and enjoy
gem 'activeadmin'
and
gem "ckeditor"
I'd like for my 'content' field to use ckeditor.
In my past apps, I render ckeditor in a form like this:
<%= form_for #resource do |f| %>
<div class="field">
<%= f.label :content %>
<br />
<%= cktext_area_tag("page_part[content]", #page_part.content) %>
</div>
...
<% end %>
Now i just added activeadmin to my stack and like what i see so far. So, I read that you can customize the form like so by editing the app/admin/#{resource}.rb file:
ActiveAdmin.register NewsItem do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "NewsItem", :multipart => true do
f.input :title
f.input :content
f.input :photo
#NOT WORKING
cktext_area_tag("news_item[content]", #news_item.content)
#NOT WORKING
end
f.buttons
end
end
How can i get this form helper to work in active_admin, and what would i put in place of #news_item.content. #news_item is null... So right now I'm a bit confused.
When I try even witout reference to #news_item like so:
cktext_area_tag("news_item[content]", 'i cant be edited properly')
I still get:
undefined method `cktext_area_tag' for #<ActiveAdmin::DSL:0x00000007e02250>
Any help would be appreciated!
Ok,
Answer was pretty simple.
Taken from active admin's own documentation page: http://activeadmin.info/docs/5-forms.html
ActiveAdmin.register Post do
form :partial => "form"
end
Then I was able to use any form helper tags I wanted to:
<%= javascript_include_tag "/javascripts/ckeditor/ckeditor.js" %>
<%= semantic_form_for [:admin, #news_item], :multipart => true do |f| %>
<%= f.inputs :title, :photo %>
<%= cktext_area_tag("news_item[content]", #news_item.content) %>
<% end %>
You can try
f.template.some_view_method
I've been looking at the new options available in HTML5 forms, such as declaring input types as "email", "url", and "number", as described here.
How can I use these in conjunction with the rails form builders? I have tried
<% form_for #user do |f| %>
<%= f.email :email, {:placeholder => 'user#domain.com'} %>
<% end %>
But that does not work. I've also tried
<% form_for #user do |f| %>
<%= f.text_field :email, {:placeholder => 'user#domain.com', :type => :email} %>
<% end %>
But the type is still "text" and not overridden. Is it possible, or is this something that will need to be addressed in Rails itself?
Looks like there is currently an open ticket and patch for adding the HTML5 form input types. If you can't wait until the patch is accepted, you could apply the patch locally by freezing the actionpack gems and applying the patch or making an initializer that add the extra methods.
Of course the other option is adding the fields manually without a form helper:
<% form_for #user do |f| %>
<%= tag(:input, {:type => :email, :value => f.object.email} %>
<% end %>
There is now an email_field tag.