-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from BlackPearl96/edit_rooms
edit room
- Loading branch information
Showing
19 changed files
with
331 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class RoomImage < ApplicationRecord | ||
belongs_to :room | ||
mount_uploader :image, ImageUploader | ||
|
||
validates :image, presence: true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
class ImageUploader < CarrierWave::Uploader::Base | ||
# Include RMagick or MiniMagick support: | ||
# include CarrierWave::RMagick | ||
include CarrierWave::MiniMagick | ||
|
||
# Choose what kind of storage to use for this uploader: | ||
storage :file | ||
# storage :fog | ||
|
||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
def store_dir | ||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
end | ||
|
||
# Provide a default URL as a default if there hasn't been a file uploaded: | ||
# def default_url | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') | ||
# end | ||
|
||
# Process files as they are uploaded: | ||
# process :scale => [200, 300] | ||
# | ||
# def scale(width, height) | ||
# # do something | ||
# end | ||
|
||
# Create different versions of your uploaded files: | ||
version :thumb do | ||
process resize_to_fit: [150, 150] | ||
end | ||
|
||
# Add a white list of extensions which are allowed to be uploaded. | ||
# For images you might use something like this: | ||
def extension_white_list | ||
%w[jpg jpeg gif png] | ||
end | ||
|
||
# Override the filename of the uploaded files: | ||
# Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
# def filename | ||
# "something.jpg" if original_filename | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
= form_for [:manager, @room] do |f| | ||
= render "shared/manager/error_messages", object: @room | ||
|
||
= f.label :name, class: "col-form-label" | ||
= f.text_field :name, class: "form-control", required: true | ||
|
||
= f.label :locations, class: "col-form-label" | ||
= f.select :location_id, options_for_select(build_location_for_rooms, | ||
selected: f.object.location_id), {include_blank: t("please_choose_one")}, | ||
{class: "form-control", required: true} | ||
|
||
= f.label :type_room, class: "col-form-label" | ||
= f.select :type_room, options_for_select(select_of_types, | ||
selected: f.object.type_room), {include_blank: t("please_choose_one")}, | ||
{class: "form-control", required: true} | ||
|
||
= f.label :address, class: "col-form-label" | ||
= f.text_field :address, class: "form-control", required: true | ||
|
||
= f.label :guest, class: "col-form-label" | ||
= f.number_field :guest, class: "form-control", required: true | ||
|
||
= f.label :acreage, class: "col-form-label" | ||
= f.text_field :acreage, class: "form-control", required: true | ||
|
||
= f.label :bed_room, class: "col-form-label" | ||
= f.number_field :bed_room, class: "form-control", required: true | ||
|
||
= f.label :bath_room, class: "col-form-label" | ||
= f.number_field :bath_room, class: "form-control", required: true | ||
|
||
= f.label :description, class: "col-form-label" | ||
= f.text_area :description, class: "form-control", required: true | ||
|
||
= f.label :image, class: "col-form-label" | ||
.show-image | ||
= f.fields_for :room_images do |builder| | ||
.nested-fields | ||
- if builder.object.image? | ||
= image_tag builder.object.image.thumb.url, class: "thumb-image" | ||
= link_to_remove_association "", builder, class: "nested-image btn" | ||
= f.file_field :image, multiple: true, name: "room_images[image][]", | ||
class: "form-control preview-image", presence: true | ||
#preview | ||
.submit | ||
= f.submit yield(:button_title), class: "create-room btn btn-outline-primary" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.nested-fields | ||
= f.file_field :image, multiple: true, name: "room_images[image][]", | ||
class: "form-control preview-image", presence: true | ||
= link_to_remove_association "remove", f, class: "btn btn-danger" |
Oops, something went wrong.