Introduce basic views for organization

organization#index
organizaton#new and organization#edit
This commit is contained in:
shlok007 2017-05-31 19:31:42 +05:30
parent a06dc84eb0
commit b1fac33420
5 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,41 @@
class OrganizationsController < ApplicationController
load_and_authorize_resource :organization
def index
@organizations = Organization.all
end
def create
@organization = Organization.new(organization_params)
if @organization.save
redirect_to organizations_path,
notice: 'Organization successfully created'
else
redirect_to new_organization_path,
error: @organization.errors.full_messages.join(', ')
end
end
def new
@organization = Organization.new
end
def edit
end
def update
if @organization.update_attributes(organization_params)
redirect_to organizations_path,
notice: 'Organization successfully updated'
else
redirect_to edit_organization_path(@organization),
error: @organization.errors.full_messages.join(', ')
end
end
private
def organization_params
params.require(:organization).permit(:name, :description, :picture)
end
end

View file

@ -0,0 +1,13 @@
= semantic_form_for(@organization) do |f|
= f.inputs name: 'Organization details' do
= f.input :name, as: :string, required: true
= f.input :description, input_html: { rows: 5 }, placeholder: 'Decribe about your organization..'
= image_tag f.object.picture.thumb.url if f.object.picture?
- if @organization.picture
= image_tag(@organization.picture.thumb.url, width: '20%')
= f.input :picture
%p.text-right
- if @organization.new_record?
= f.submit 'Create Organization', class: 'btn btn-success'
- else
= f.submit 'Update Organization', class: 'btn btn-success'

View file

@ -0,0 +1,4 @@
.container
.row
.col-md-12
= render 'form'

View file

@ -0,0 +1,17 @@
.container
.row
.col-md-12.page-header
%h1
Organizations
.btn-group.pull-right
= link_to 'Add new', new_organization_path, class: 'btn btn-mini btn-success'
- @organizations.each do |organization|
.col-md-4
.thumbnail
= image_tag(organization.picture.thumb.url, width: '20%')
.caption
%h4
= organization.name
%button.btn.btn-success Know More
= link_to 'Edit', edit_organization_path(organization), class: 'btn btn-mini btn-default'

View file

@ -0,0 +1,4 @@
.container
.row
.col-md-12
= render 'form'