-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing the creation and editing of interests, for #6
- Loading branch information
Tassos (nakano) Natsakis
committed
Apr 9, 2015
1 parent
592d023
commit a9c1989
Showing
4 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,37 @@ def show | |
@is_member = is_member? | ||
end | ||
|
||
def edit | ||
@interest = Interest.find(params[:id]) | ||
end | ||
|
||
def new | ||
@interest = Interest.new | ||
end | ||
|
||
def create | ||
@interest = Interest.new(interest_params) | ||
if @interest.save! | ||
flash[:success]="You created new interest successfully!" | ||
redirect_to interests_path | ||
else | ||
flash[:alert]="Something went wrong :( Please report this bug at [email protected]" | ||
render_to new_interest_path | ||
end | ||
end | ||
|
||
def update | ||
@interest = Interest.find(params[:id]) | ||
|
||
if @interest.update(interest_params) | ||
flash[:success]="You updated your interest group successfully!" | ||
redirect_to @interest | ||
else | ||
flash[:alert]="Something went wrong :( Please report this bug at [email protected]" | ||
render 'edit' | ||
end | ||
end | ||
|
||
def join | ||
if is_member? | ||
flash[:alert]='You are already part of this group' | ||
|
@@ -32,6 +63,10 @@ def leave | |
|
||
private | ||
|
||
def interest_params | ||
params.require(:interest).permit(:initiator, :title, :description) | ||
end | ||
|
||
def sort_column | ||
Interest.column_names.include?(params[:sort]) ? params[:sort] : 'created_at' | ||
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,22 @@ | ||
<div class="row"> | ||
<div class="col-md-10"> | ||
<%= form_for (@interest) do |f| %> | ||
|
||
<div class="form-group"> | ||
<%= f.label :title %> | ||
<%= f.text_field :title, required: 'required', placeholder: 'Title', class: 'form-control' %> | ||
</div> | ||
<div class="form-group"> | ||
<%= f.label :description %> | ||
<%= f.text_area :description, required: 'required', placeholder: 'Description', class: 'form-control', rows: 10 %> | ||
</div> | ||
|
||
<%= f.hidden_field :initiator, {value: current_user.id} %> | ||
<% if dom_id == "edit_announcement"%> | ||
<%= button_to "Edit!", edit_interest_path(@interest), class: "btn btn-success" %> | ||
<%else%> | ||
<%= f.submit "Create", class: "btn btn-success" %> | ||
<%end%> | ||
<%end%> | ||
</div> | ||
</div> |
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 @@ | ||
<%= render 'form', dom_id: 'edit_announcement'%> |
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 @@ | ||
<%= render 'form', dom_id: 'new_announcement'%> |