forked from hmlON/room538
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change room activities update to ajax call
- Loading branch information
Showing
11 changed files
with
163 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class RoomActivitiesController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :require_room_presence | ||
|
||
def new | ||
@room_activities = @room.room_activities.unscoped | ||
end | ||
|
||
def create | ||
@room_activity = RoomActivity.new(room_activity_params) | ||
if @room_activity.save | ||
# redirect_to dashboard_path, notice: "RoomActivity \"#{@room_activity.name}\" has been successfully created" | ||
flash[:notice] = "RoomActivity \"#{@room_activity.name}\" has been successfully created" | ||
else | ||
flash[:alert] = @room_activity.errors.full_messages.join(',') # 'There was an error creating this activity!' | ||
end | ||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
def update | ||
room_activity = RoomActivity.find(params[:id]) | ||
room_activity.update(room_activity_params) | ||
# respond | ||
end | ||
|
||
def destroy | ||
room_activity = RoomActivity.find(params[:id]) | ||
if room_activity.destroy | ||
flash[:notice] = "Activity \"#{room_activity.name}\" has been successfully deleted" | ||
else | ||
flash[:alert] = 'There was an error deleting this activity!' | ||
end | ||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
private | ||
|
||
def set_room | ||
@room = current_user.room | ||
end | ||
|
||
def room_activity_params | ||
params.require(:room_activity) | ||
.permit(:name, :enabled) | ||
.merge(room_id: @room.id) | ||
# .tap { |params| params[:creator_id] = current_user.id } | ||
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
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 @@ | ||
.form.row | ||
- @room_activities.each do |activity| | ||
.checkbox.col-sm-6 | ||
label for="#{dom_id(activity)}" | ||
= check_box_tag 'activity_ids[]', activity.id, activity.enabled?, id: dom_id(activity), class: "js-update-room-activity", data: { id: activity.id } | ||
= activity.name | ||
/ - unless activity.creator.nil? | ||
/ = link_to '×'.html_safe, room_activity_path(id: activity.id), method: :delete |
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 @@ | ||
= simple_form_for(RoomActivity.new) do |f| | ||
= f.input :name, placeholder: 'Name', label: false | ||
.actions.text-center | ||
= f.button :submit, 'Create activity', class: 'btn btn-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,12 @@ | ||
= title 'Step 2: Add activities to your room' | ||
h3.text-center We created some activities for you | ||
p.text-center.text-muted You can delete them, if you don't like them | ||
= render 'edit_form' | ||
|
||
h3.text-center Or you can create your own activities | ||
= render 'form' | ||
|
||
.pull-right | ||
= link_to dashboard_path, class: 'btn btn-primary' do | ||
| Continue to Dashboard | ||
= fa_icon('arrow-right') |
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