Last active
February 3, 2016 20:09
-
-
Save andreas-it-dev/f38ff1dd1b5f580287ae to your computer and use it in GitHub Desktop.
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
<div class="col-md-12 center-text"> | |
<h1><%= @stock.name %> (<%= @stock.symbol %>)</h1> | |
<small> | |
<% if signed_in? %> | |
<%= link_to('Stocks list', stocks_path) %> | |
<% if current_user.admin? %> | |
<%= link_to '| Edit Stock', edit_stock_path(@stock), class: 'button' %> | |
| <%= link_to 'Delete Stock', @stock, | |
method: :delete, | |
data: {confirm: 'Are you sure you want to permanently delete this stock?'}, | |
class: 'button' %> | |
<% end %> | |
<% end %> | |
</small> | |
</div> | |
<div class="row"> | |
<div class="col-xl-4"> | |
<div id="googlechart" class="col-md-6"></div> | |
<%= render_chart @chart, 'googlechart' %> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-xl-2 small"> | |
<h4>Address</h4> | |
<address><%= @stock.address %><br /> | |
<strong>Phone:</strong> <%= @stock.phone %><br /> | |
<strong>eMail:</strong> <%= @stock.email %><br /> | |
<strong>web:</strong> <%= link_to(@stock.website, @stock.website, :target => "_blank" ) %> | |
</address> | |
</div> | |
<div class="col-xl-6 small"> | |
<h4>Company Summary</h4> | |
<%= @stock.profile %> | |
</div> | |
<div class="col-xl-4 small"> | |
<h4>Index Memberships</h4> | |
<ul> | |
<% @stock.indexes.each do |i| %> | |
<dl><%= link_to(i.name, i) %></dl> | |
<% end %> | |
</ul> | |
</div> | |
</div> | |
<% provide(:title, "Show Stock #{@stock.name}") %> |
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
class StocksController < ApplicationController | |
before_action :set_stock, except: [:index, :new, :create] | |
def index | |
@stocks = Stock.all | |
respond_to do |format| | |
format.html | |
format.json { render json: StocksDatatable.new(view_context) } | |
end | |
end | |
def show | |
data_table = GoogleVisualr::DataTable.new | |
# Add Column Headers | |
data_table.new_column('date', 'Date' ) | |
data_table.new_column('number', 'Close') | |
# Add Rows and Values | |
data_table.add_rows(@stock.daily_prices.where('date > ?', 1.year.ago).pluck(:date, :close)) | |
option = { width: 400, height: 250, title: @stock.symbol, legend: {position: 'none'}, chartArea: {width: '80%'} } | |
@chart = GoogleVisualr::Interactive::AreaChart.new(data_table, option) | |
end | |
def new | |
@stock = Stock.new | |
end | |
def create | |
@stock = Stock.new(stock_params) | |
if @stock.save | |
redirect_to stocks_url | |
else | |
render :new | |
end | |
end | |
def edit | |
end | |
def update | |
if @stock.update(stock_params) | |
redirect_to @stock, notice: "Security successfully updated!" | |
else | |
render :edit | |
end | |
end | |
def destroy | |
@stock.destroy | |
redirect_to stocks_url, notice: "Security successfully deleted!" | |
end | |
private | |
def stock_params | |
params.require(:stock). | |
permit(:name, :symbol, :profile, :address, :phone, :email, :website) | |
end | |
def set_stock | |
@stock = Stock.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment