Created
January 28, 2013 23:17
-
-
Save indrekj/4660197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Admin | |
class CategoriesController < BaseController | |
def new | |
@form = CategoryForm.new | |
end | |
def create | |
@form = CategoryForm.new(params[:category]) | |
if @form.valid? | |
category = CreatesCategory.new( | |
@form.attributes.merge(company_id: current_company.id) | |
).call | |
show_notice | |
redirect_to admin_category_products_path(category.id) | |
else | |
render :new | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CategoryForm | |
include FunkyForm | |
IMAGES = %w( | |
not_important | |
) | |
model "Category" | |
attribute :id, Integer | |
attribute :name, String | |
attribute :image, String, default: IMAGES.first | |
validates :name, presence: true, length: {within: 3..20} | |
validates :image, presence: true, inclusion: {in: IMAGES} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= simple_form_for [:admin, @form], html: {class: "form-horizontal"} do |f| | |
= f.input :name, placeholder: "Category name" | |
= f.input :image, as: :hidden | |
.control-group.string.required | |
= f.label :image | |
.controls.category-images | |
- CategoryForm::IMAGES.each do |image| | |
/ removed | |
.form-actions | |
= f.button :submit, class: "btn-primary" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment