-
Notifications
You must be signed in to change notification settings - Fork 3
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 #21 from x3igh7/news
News
- Loading branch information
Showing
32 changed files
with
216 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
class CommentsController < ApplicationController | ||
def create | ||
if not params[:match_id].nil? | ||
if not params[:news_id].nil? | ||
@user = current_user | ||
@news = News.find(params[:news_id]) | ||
@comment = @news.comments.build(:content => params[:comment][:content], :user_id => @user.id ) | ||
if @comment.save | ||
flash[:notice] = "Comment accepted" | ||
redirect_to :back | ||
else | ||
flash[:alert] = @comment.errors.full_messages.first | ||
redirect_to news_path(@news) | ||
end | ||
elsif params[:match_id].nil? | ||
@match = Match.find(params[:match_id]) | ||
@home_team = @match.home_team.team | ||
@away_team = @match.away_team.team | ||
if current_user.is_team_member?(@home_team) or current_user.is_team_member?(@away_team) | ||
@comment = @match.comments.build( :content => params[:comment][:content], :user_id => current_user.id ) | ||
if @comment.save | ||
flash[:notice] = "Comment accepted" | ||
redirect_to :back | ||
else | ||
flash[:alert] = @comment.errors.full_messages.first | ||
redirect_to tournament_match_path(@match.tournament, @match) | ||
return | ||
end | ||
end | ||
end | ||
|
||
#TODO: cases for other comment types e.g. tournament, news comments | ||
flash[:alert] = @comment.errors.full_messages.first | ||
redirect_to tournament_match_path(@match.tournament, @match) | ||
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
class HomeController < ApplicationController | ||
|
||
def home | ||
@news = News.where(newsable_id: 0) | ||
if user_signed_in? | ||
@teams = current_user.teams | ||
@tournaments = current_user.tournaments | ||
@user = current_user | ||
@teams = @user.teams | ||
@tournaments = @user.tournaments | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
class NewsController < ApplicationController | ||
|
||
def show | ||
@news = News.find(params[:id]) | ||
end | ||
def show | ||
@news = News.find(params[:id]) | ||
@comments = @news.comments | ||
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
class News < ActiveRecord::Base | ||
attr_accessible :headline, :description, :content, :newsable_id | ||
attr_accessible :headline, :description, :content, :newsable_id, :user, :user_id | ||
|
||
belongs_to :newsable, :polymorphic => true | ||
has_many :comments, :as => :commentable, :dependent => :destroy | ||
belongs_to :user | ||
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
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,2 @@ | ||
<h1>edit news</h1> | ||
<%= render 'admin_news_form' %> |
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 |
---|---|---|
@@ -1,8 +1,2 @@ | ||
<h1>add news</h1> | ||
<%= simple_form_for([:admin, @news]) do |f| %> | ||
<%= f.input :newsable_id, collection: @sources, label: "Source" %> | ||
<%= f.input :headline %> | ||
<%= f.input :description %> | ||
<%= f.input :content, as: :text, :input_html => { :rows => "15", :class =>"span5"} %> | ||
<%= f.submit "Save" %> | ||
<% end %> | ||
<%= render 'admin_news_form' %> |
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,9 @@ | ||
<%= simple_form_for([:admin, @news]) do |f| %> | ||
<% if @news.newsable_type.nil? %> | ||
<%= f.input :newsable_id, collection: @sources, label: "Source", include_blank: true %> | ||
<% end %> | ||
<%= f.input :headline %> | ||
<%= f.input :description %> | ||
<%= f.input :content, as: :text, :input_html => { :rows => "15", :class =>"span5"} %> | ||
<%= f.submit "Save" %> | ||
<% 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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
<% @user = User.find(comment.user_id) %> | ||
<div class="comments-inner"> | ||
<div> | ||
<span class="important"><%= link_to @user.username, user_path(@user) %></span> | ||
<span class="important"><%= link_to comment.user.username, user_path(comment.user) %></span> | ||
<div style="float:right;" class="faded"> | ||
<%= comment.updated_at %> | ||
</div> | ||
</div> | ||
<div> | ||
<%= comment.content %> | ||
</div> | ||
</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,14 @@ | ||
<% if @news.any? %> | ||
<% @news.each do |news| %> | ||
<div class="content-inner-inner"> | ||
<p class="headline"><%= news.headline %></p> | ||
|
||
<p style="font-size:10px">Created at <%= news.created_at %> by <%= news.user.username %></p> | ||
|
||
<p><%= news.description %></p> | ||
<p><%= link_to "read more...", news_path(news)%></a></p> | ||
</div> | ||
|
||
|
||
<% 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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
<div class="content-outer comments" style="width:500px;"> | ||
<div class="content-inner-inner" id="comments"> | ||
<h1>comments</h1> | ||
<% @comments = @match.comments %> | ||
<% if @comments.any? %> | ||
<% @comments.each do |comment| %> | ||
<%= render :partial => "comment", :locals => { :comment => comment } %> | ||
<% end %> | ||
<% @comments.each do |comment| %> | ||
<%= render :partial => "comment", :locals => { :comment => comment } %> | ||
<% end %> | ||
<% else %> | ||
No comments yet. | ||
<% end %> | ||
No comments yet. | ||
<% end %> | ||
</div> | ||
</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,12 @@ | ||
<h1><%= @news.headline %></h1> | ||
<p style="font-size:10px">Created at <%= @news.created_at %> by <%= @news.user.username %></p> | ||
<div class="content-inner"> | ||
<div class="content-inner-inner"> | ||
<p><%=raw @news.content %></p> | ||
</div> | ||
<%= render('show_comments') %> | ||
<% if user_signed_in? %> | ||
<%= render('submit_news_comment') %> | ||
<% end %> | ||
</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
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,9 @@ | ||
<div class="content-outer comments" style="width:500px;"> | ||
<div class="content-inner-inner"> | ||
<h1>submit comment</h1> | ||
<%= simple_form_for [ @news, Comment.new ], :id => :comment do |f| %> | ||
<%= f.input :content, :label => false, :as => :text, :input_html => { :cols => 50, :rows => 5 } %> | ||
<%= f.submit "Submit" %> | ||
<% 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
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 |
---|---|---|
@@ -1,7 +1,3 @@ | ||
<h1><%= @news.headline %></h1> | ||
<div class="content-inner"> | ||
<p><%= @news.description %></p> | ||
<div class="content-inner-inner"> | ||
<p><%=raw @news.content %></p> | ||
</div> | ||
</div> | ||
<%= render 'show_news' %> | ||
<%= link_to "Back", :back %> | ||
<div class="spacer"></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
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
Oops, something went wrong.