iT邦幫忙

DAY 12
0

Rails. Really, I love study.系列 第 12

顯現。

  • 分享至 

  • xImage
  •  

"大千世界盡在眼中"

現在來做點擊姓名,可以跳到單獨頁面顯現資料

到 controller 寫好秀的 action

app/controllers/girbs_controller.rb

class GirbsController < ApplicationController
  def index
    @girbs = Girb.all
  end
  def like
    @girb = Girb.find(params[:id])
    @girb.like += 1;
    @girb.save
    redirect_to(girbs_path)
  end
  def on_click_bang
    @girb = Girb.find(params[:id])
    @girb.bangs.create
    redirect_to(girbs_path)
  end
    def new
    @girb = Girb.new
  end

  def create
    @girb = Girb.new(girb_params)
    if @girb.save
      redirect_to(girbs_path)
    else
      render :new
    end
  end

  def show
    @girb = Girb.find(params[:id])
  end

  private

  def girb_params
    params.require(:girb).permit(:name, :email, :like)
  end
end

刻畫面

app/views/girbs/show.html.erb

<div class="container">
<%= form_for @girb, :html => {:class => "form-horizontal center"} do |f| %>
<div class="form-group">
<%= f.label :name, "Name:", class: "col-md-3 control-label" %>
<div class="col-md-7">
<%= f.text_field :name, class: "form-control" %>
</div>
</div>
<div class="form-group">
<%= f.label :email, "Email:", class: "col-md-3 control-label" %>
<div class="col-md-7">
<%= f.text_field :email, class: "form-control" %>
</div>
</div>
<div class="form-group">
<%= f.label :like, "Like:", class: "col-md-3 control-label" %>
<div class="col-md-7">
<%= f.text_field :like, class: "form-control" %>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
</div>
<div class="col-md-7">
<%= link_to "back...", :back, class: "pull-right"%>
</div>
</div>
<% end %>
</div>

到 index 寫好鍵結

app/views/girbs/index.html.erb

<div class="container">
<h1>Index Page of Girb</h1>
<div class="row">
<% @girbs.each do |girb| %>
<div class="col-lg-4 col-md-6"> 
<div class="panel panel-default">
<div class="panel-body">
<span style="color:#0000FF"><%= link_to girb_path(girb) do %></span>
<div style="font-size:22px;color:#0099FF">
<%= girb.name %>
</div>
<span style="color:#0000FF"><% end %></span>
<div ><%= girb.email %></div>
<div style="padding-top:3px">
<%= link_to like_girb_path(girb.id), method: :post do %>
<i class="fa fa-heart" style="color:red"> <%= girb.like %></i>
<% end %>
<span class="pull-right">
<%= link_to on_click_bang_girb_path(girb.id), method: :post do %>
<i class="fa fa-rocket" > <%= girb.bangs.size %></i>
<% end %>
</span>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>


上一篇
新生。
下一篇
更新。
系列文
Rails. Really, I love study.30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言