Ruby on Rails初心者です。
独学で学んでおります。
スポーツ選手の一覧を登録でき歴史やハイライトを表示できるwebサイトを作っております。
まず、最初のページにチーム一覧があり、そこからチームを取り出し選手などの概要をつけました。 has_many,belongs_toの関係にしております。
そこから選手の名前をクリックするとyoutubeのハイライト画面に飛ばすようにしたいのですがそこがうまくいかず困っています。
初心者なのでうまく説明できず申し訳ございません。
一度相互関係を作ったものから選手の名前を抜き出し個々にハイライトをつけたいと思っております。
色々と試しているのですが全く答えに行き着かずかなり苦戦しています。
どうか詳しい方ご教授いただけると助かります。
何か必要なコードの記載があればすぐに追記いたします。
teams_controller.rb
class TeamsController < ApplicationController def index @teams = Team.all end def show @team = Team.find params[:id] end def new end def edit @team = Team.find params[:id] end def create @team = Team.new(team_params) @team.save redirect_to team_path(@team) end def update @team = Team.find params[:id] if @team.update(team_params) redirect_to @team else render 'edit' end end def destroy @team = Team.find params[:id] @team.destroy redirect_to team_path end def team_params params.require(:team).permit(:title, :body, :image) end end
players_controller.rb
class PlayersController < ApplicationController def index @team = Team.find params[:team_id] end def create @team = Team.find params[:team_id] @team.players.create(player_params) redirect_to team_path(@team) end def destroy @team = Team.find params[:team_id] @player = @team.players.find params[:id] @player.destroy redirect_to team_path(@team) end def player_params params.require(:player).permit(:name, :body, :image) end end
追記 players_controller.rb
class PlayersController < ApplicationController def show @player = Player.find params[:id] end def create @team = Team.find params[:team_id] @team.players.create(player_params) redirect_to team_path(@team) end def destroy @team = Team.find params[:team_id] @player = @team.players.find params[:id] @player.destroy redirect_to team_path(@team) end def player_params params.require(:player).permit(:name, :body, :image) end end
(players)show.html.erb
<h2>High Light</h2> <h3><%= @player.name %><br></h3> <iframe width="640" height="480" src="https://www.youtube-nocookie.com/embed/13YeR5zIGbo?start=109" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><br> <%= link_to 'Player List', teams_path %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/02 14:16
2019/05/12 12:30 編集
2019/05/15 13:30