我有一个主页 HomeController 这会加载主页视图,该主页视图在页面顶部有一些标题内容和其他 html。我在页面上的所有内容下方还有一个故事板,然后是其他一些主页 html 内容。现在故事板也有一个模型视图控制器。我的问题是如何让我的视图加载到主页上的故事板区域。我是否需要从我的 HomeController 到我的 StoryBoard 控制器进行通信,以将 StoryBoard 视图放置到故事板要显示的主视图区域中。
我不确定如何建立两者之间的关系。
用代码更新。
这段代码实际上是由 rails 生成的脚手架代码。希望这将有助于弄清楚我想要做什么。我只想能够将我的故事板渲染到主视图故事板 div 标签中。
家庭控制器
class HomeController < ApplicationController
def index
end
end
主页视图
<body>
<div id="description">
<div id="info">
<p class="title">Sed ut perspiciatis unde omnis</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo</p>
</div>
</div>
<div id="soryboard">
// add story board view here
</div>
<div id="section2">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo</p>
</div>
</body>
故事板控制器
class StoryboardsController < ApplicationController
# GET /storyboards
# GET /storyboards.json
def index
@storyboards = Storyboard.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @storyboards }
end
end
# GET /storyboards/1
# GET /storyboards/1.json
def show
@storyboard = Storyboard.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @storyboard }
end
end
# GET /storyboards/new
# GET /storyboards/new.json
def new
@storyboard = Storyboard.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @storyboard }
end
end
# GET /storyboards/1/edit
def edit
@storyboard = Storyboard.find(params[:id])
end
# POST /storyboards
# POST /storyboards.json
def create
@storyboard = Storyboard.new(params[:storyboard])
respond_to do |format|
if @storyboard.save
format.html { redirect_to @storyboard, notice: 'Storyboard was successfully created.' }
format.json { render json: @storyboard, status: :created, location: @storyboard }
else
format.html { render action: "new" }
format.json { render json: @storyboard.errors, status: :unprocessable_entity }
end
end
end
# PUT /storyboards/1
# PUT /storyboards/1.json
def update
@storyboard = Storyboard.find(params[:id])
respond_to do |format|
if @storyboard.update_attributes(params[:storyboard])
format.html { redirect_to @storyboard, notice: 'Storyboard was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @storyboard.errors, status: :unprocessable_entity }
end
end
end
# DELETE /storyboards/1
# DELETE /storyboards/1.json
def destroy
@storyboard = Storyboard.find(params[:id])
@storyboard.destroy
respond_to do |format|
format.html { redirect_to storyboards_url }
format.json { head :no_content }
end
end
end
故事板视图
<h1>Listing storyboard</h1>
<table>
<tr>
<th>Image url</th>
<th>Title</th>
<th>Description</th>
<th>Category</th>
<th>Link</th>
<th>Width</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @storyboards.each do |storyboard| %>
<tr>
<td><%= storyboard.image_url %></td>
<td><%= storyboard.title %></td>
<td><%= storyboard.description %></td>
<td><%= storyboard.category %></td>
<td><%= storyboard.link %></td>
<td><%= storyboard.width %></td>
<td><%= link_to 'Show', storyboard %></td>
<td><%= link_to 'Edit', edit_storyboard_path(storyboard) %></td>
<td><%= link_to 'Destroy', storyboard, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Storyboard', new_storyboard_path %>