Skip to content

Commit

Permalink
Implementing the creation and editing of interests, for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Tassos (nakano) Natsakis committed Apr 9, 2015
1 parent 592d023 commit a9c1989
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/controllers/interests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions app/views/interests/_form.html.erb
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>
1 change: 1 addition & 0 deletions app/views/interests/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form', dom_id: 'edit_announcement'%>
1 change: 1 addition & 0 deletions app/views/interests/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form', dom_id: 'new_announcement'%>

0 comments on commit a9c1989

Please sign in to comment.