Active Admin Text Input are Big Instead of just a line - ruby-on-rails-4

this problem is across my rails app... The text input boxes are huge instead of simply being line ones.
in app/admin/restaurant.rb
form do |f|
f.inputs do
f.input :name, required: true
f.input :servesCuisine
f.input :description
f.input :currenciesAccepted, as: :select, collection:Restaurant.available_currencies
f.input :priceRange, as: :select, collection: Restaurant.price_range
f.input :paymentAccepted
f.input :email, as: :email
f.input :telephone, as: :phone
f.input :faxNumber, as: :phone
f.input :longitude
f.input :latitude
f.input :image, as: :file
end
f.actions
end
Huge texbox
The problem also occurs on my login page where my email field is also gigantic. How can I fix this?
Thanks

You should use as option with f.input like -
f.input :servesCuisine, as: :string
f.input :description, as: :string
You can edit your admin_users.rb file
f.input :email, as: :string
Hope this helps!!

LHH is 100% spot-on, however if you need a bit more control but don't want to involve CSS, you can do:
f.input :title, label: 'Title tag', input_html: {cols: "5", rows: "1"}

Related

ActiveAdmin Nested Form multiple select

I'm trying to get the product_suppliers to update via the product form. The form displays all suppliers in the supplier table but it doesn't update the join table. Not sure where the error lies. Index and show show correct details but edit is not updating the join table. Starting to go around and around in circles on this one.
Update: Changing the form to the below has got me close. But still not updating the join table. However delete works as expected if i manually add rows to the join table. They display and can be deleted. Saving adds new product_id into the row just not the associated supply_company_id value. I figure its an attribute issue but i cant see it.
app/models/product.rb
class Product < ActiveRecord::Base
### shortned for clarity
has_many :product_suppliers, :foreign_key => 'product_id'
has_many :supply_companies, :through => :product_suppliers
accepts_nested_attributes_for :product_suppliers, :allow_destroy => true
end
app/models/supply_company.rb
class SupplyCompany < ActiveRecord::Base
has_many :products, :through => :product_suppliers
has_many :product_suppliers, :foreign_key => 'supply_company_id'
end
app/models/product_supplier.rb
class ProductSupplier < ActiveRecord::Base
belongs_to :product
belongs_to :supply_company
accepts_nested_attributes_for :product
accepts_nested_attributes_for :supply_company
end
/app/admin/product.rb
ActiveAdmin.register Product do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
permit_params :id, :product_name, :product_description, :product_type_id, :product_category_id, :product_colour_id, :product_size_id,
product_images_attributes: [:id, :product_id, :product_image, :_destroy],
product_types_attributes: [:id, :product_type],
product_catergories_attributes: [:id, :product_category],
product_colour_attributes: [:id, :product_colour],
product_size_attributes: [:id, :product_size],
product_suppliers_attributes: [:id, :product_id, :supply_company_id, :_destroy],
supply_companies_attributes: [:id, :company_name]
form(:html => {:multipart => true}) do |f|
f.inputs "Product Details" do
f.input :id
f.input :product_name
f.input :product_description
#######################################################################
# Problem Lies with this piece of code Not saving the supply_company_id
# when adding a new row or updating the old rows. Delete works fine.
# cant see the error in models or permited_params.......
#######################################################################
f.inputs "Suppliers" do
f.has_many :product_suppliers do |ff|
ff.input :supply_company_id, as: :select, multiple: true, collection: SupplyCompany.all.map {|u| [u.company_name.to_s, u.id]}
ff.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove supplier'
end
end
########################################################
f.input :product_type_id, :as => :select, :collection => ProductType.all.map {|u| [u.product_type.to_s, u.id]}
f.input :product_category_id, :as => :select, :collection => ProductCategory.all.map {|u| [u.product_category.to_s, u.id]}
f.input :product_colour_id, :as => :select, :collection => ProductColour.all.map {|u| [u.product_colour.to_s, u.id]}
f.input :product_size_id, :as => :select, :collection => ProductSize.all.map {|u| [u.product_size.to_s, u.id]}
end
f.inputs "Product images" do
f.has_many :product_images do |p|
p.input :product_image, :as => :file, :label => "Image",:hint => image_tag(p.object.product_image.url(:thumb))
p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
end
end
f.actions
end
product_suppliers_schema
create_table "product_suppliers", force: true do |t|
t.integer "product_id"
t.integer "supply_company_id"
t.datetime "created_at"
t.datetime "updated_at"
end
Update:
Changing the form to the below has got me close. But still not updating the join table. However delete works as expected if i manually add rows to the join table. They display and can be deleted.
Saving adds new product_id into the row just not the associated supply_company_id value. I figure its an attribute issue but i cant see it.
f.inputs "Suppliers" do
f.has_many :product_suppliers do |ff|
ff.input :supply_company_id, as: :select, multiple: true, collection: SupplyCompany.all.map {|u| [u.company_name.to_s, u.id]}
ff.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove supplier'
end
end
Turns out it was the multipart: :true in the code. Once I removed it from the below code everything worked as expected.
form(:html => {:multipart => true}) do |f|
f.inputs "Product Details" do
f.input :id
f.input :product_name
f.input :product_description
f.has_many :product_supply_companies do |ff|
###############################################
#REMOVED multipart: :true from the line below
###############################################
ff.input :supply_company_id, as: :select, collection: SupplyCompany.all.map {|u| [u.company_name.to_s, u.id]}
ff.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove supplier'
end
f.input :product_type_id, :as => :select, :collection => ProductType.all.map {|u| [u.product_type.to_s, u.id]}
f.input :product_category_id, :as => :select, :collection => ProductCategory.all.map {|u| [u.product_category.to_s, u.id]}
f.input :product_colour_id, :as => :select, :collection => ProductColour.all.map {|u| [u.product_colour.to_s, u.id]}
f.input :product_size_id, :as => :select, :collection => ProductSize.all.map {|u| [u.product_size.to_s, u.id]}
end
f.inputs "Product images" do
f.has_many :product_images do |p|
p.input :product_image, :as => :file, :label => "Image",:hint => image_tag(p.object.product_image.url(:thumb))
p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
end
end
f.actions
end

(Rails 4) Acts_as_taggable_on: using a model other than "Tag"

I am trying to implement the acts_as_taggable_on gem. In my set up I have a Model called Discipline which is pre-populated with about 40 names.
I also have a Model Micropost which I want to tag - using a select box containing all the names in the disciplines database. I thought that I could call the acts_as_taggable_on the Model I wanted - in this case Disciplines but its not working with my current set up.
class Micropost < ActiveRecord::Base
acts_as_taggable
acts_as_taggable_on :disciplines
end
Here is the form......
<%= simple_form_for(#micropost) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.input :tag_list, :as => :select,
:multiple => :true,
:collection => ActsAsTaggableOn::Tag.pluck(:name) %>
<%= f.text_area :content, placeholder: "What is your question?", :style => "height:75px;" %>
<%= f.submit "Post", class: "btn btn-primary" %>
<% end %>
I can tell from the documentation that there is a way to do this....but I guess I am just not getting it. Any suggestions?
I don't think you can use acts_as_taggable_on using a model other than the default Tag and Taggings models.
Alternative Approach #1
Seed your database with the pre-populated 40 Tags containing your discipline names.
Alternative Approach #2
Use bitmask_attributes for your 40 disciplines.
For example, in my application I have:
bitmask :instruments, as: [:others, :guitar, :piano, :bass, :mandolin, :banjo,
:ukulele, :violin, :flute, :harmonica, :trombone,
:trumpet, :clarinet, :saxophone, :viola, :oboe,
:cello, :bassoon, :organ, :harp, :accordion, :lute,
:tuba, :ocarina], null: false

Ruby on Rails - TinyMce works for new but not for edit

Hey guys I have this form for the NEW action that works with tinyMce
<%= f.input :titulo, :label => "Título" %>
<%= f.input :sumario, :label => "Sumário", :input_html => { :class => 'tinymce' } %>
<%= f.input :texto, :label => "Texto", :input_html => { :class => 'tinymce' } %>
<%= f.input :imagem, :label => "Imagem" %>
<%= f.input :ativa, :label => "Ativar/Desativar?", as: :boolean, boolean_style: :inline %>
<%= f.input :destaque, :label => "Em Destaque?", as: :boolean, boolean_style: :inline %>
It's actually a partial that the EDIT action will use aswell. The thing is that the tinyMce editor only shows on NEW and never shows on EDIT.
!!!EDIT: NEVER MIND! RESOLVED
NEVER MIND!
dumb question!
just needed to add this on top of the page:
<%= tinymce_assets %>
and this on the bottom:
<%= tinymce %>
I didn't have this on EDIT xD SORRY FOR THE QUESTION

Nested attributes using paperclip rails 4

I am new to rails and I am trying to work with nested attributes.
The main idea is to have a a deal(offer) model, a deal will have multiple deal_photos from paperclip.
I have already watched Ryan's Railscast for nested forms and read many articles with many tips regarding problems on the same issue but still it doesn't work for me.
Here is my Implementation:
class Deal < ActiveRecord::Base
belongs_to :user
has_many :deal_photos, dependent: :destroy
accepts_nested_attributes_for :deal_photos
end
class DealPhoto < ActiveRecord::Base
belongs_to :deal
has_attached_file :photo, :styles => { :large => "600x170", :medium => "250x250!", :thumb => "100x100>" }, :default_url => lambda { |photo| photo.instance.set_default_url}
def set_default_url
ActionController::Base.helpers.asset_path('missing.png')
end
end
In my deals controller:
class DealsController < ApplicationController
def new_deal
#deal=Deal.new()
#user= User.find(params[:id])
3.times { #deal.deal_photos.build }
end
def create
#deal = Deal.new(deal_param)
#user= User.find(params[:user_id])
if #deal.save
#user.deals << #deal
flash[:notice]="Thank you"
end
end
def edit
#deal=Deal.find(params[:deal_id])
3.times { #deal.deal_photos.build }
end
def update
#deal=Deal.find(params[:id])
if #deal.update_attributes(deal_params)
flash[:notice]="Deal updated successfully"
end
end
private
def deal_params
params.require(:deal).permit(:title, :description, :contact_num, :user_id, :deal_photos_attributes => [ :id, :caption, :photo, :deal_id])
end
Finally in my form for a new deal:
<%= form_for(:deal, :url=>{:action=>'create', :user_id=> #user.id}) do |f| %>
<label>Title<b style="color:red;">*</b>
<%= f.text_field(:title, :placeholder=>"") %>
</label>
------------more fields---------------------
<%= f.fields_for :deal_photos do |builder| %>
<div>
<%= builder.label :caption, "Image Caption" %>
<%= builder.text_field :caption %>
<%= builder.label :photo, "Image File" %>
<%= builder.file_field :photo %>
</div>
<%end%>
<%= button_tag("Create", :class=> "secondary button", :button_type => "submit") %>
(I have migrated the db for deals_photo to accept paperclip)
The above, creates a form with all fields but instead of 3 inputs for file upload shows only one. It creates 3 empty associations #deal.deal_photos but even if I choose one image to upload from the form it doesn't save it.
If you have any useful advices or another similar question please help!
What's in your deal_param method?
Do you permit deal_photos' attributes in it?
If no then do something like
def deal_params
params.require(:deal).permit(deal_attr1, deal_attr2,...., deal_photos_attributes: [:deal_photo_attr1, ...])
end
Also, do you get a deal_id in your deal_photos in view?
Finally, I was able to solve the problem in the new_deal.html.erb when I replaced the:
<%= form_for(:deal, :url=>{:action=>'create', :user_id=> #user.id}) do |f| %>
with
<%= form_for(#deal, :url=>{:action=>'create', :user_id=> #user.id}) do |f| %>
What is changed is that the second line is for the specific new deal instance. Maybe the reason that the first was not working is that the deal_photos didn't get the deal_id, as Alexphys said. But still I haven't figure out the exact reason.

Form Helper not found when using select_recurring for Ice_Cube with Formtastic and ActiveAdmin.

When using the select_recurring form helper for the Ice_Cube gem in Formtastic with ActiveAdmin I receive a unable to find input class for select_recurring error.
form do |f|
#Debugging
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :title
f.input :description, :hint => "Full description for the event"
f.input :short_description, :hint => "Shot description for the event that will be displayed as a thumbnail"
f.input :published
f.input :event_date
f.input :recurring_rule, :as => :select_recurring
end
f.actions
end
Accessing it directly (below) works for the recurring schedule element but breaks all of the rest of the formtastic f.input elements.
f.select_recurring :recurring_schedule
How can I incorporate select_recurring into ActiveAdmin?
worked for me (AA 1.0.0.pre1)
form do |f|
f.inputs do
#...
li do
f.label :recurring_rule_column
f.select_recurring :recurring_rule_column, nil, :allow_blank => true
end
#...
end
f.submit
end