我正在尝试制作两列布局。左边一栏是导航,右边一栏是内容。
Is there a way to display show.html.erb
, edit.html.erb
, and new.html.erb
at different times in the right div, when the corresponding navigation is selected, without re-loading the whole page?
我知道我可以为左侧 div 使用部分,并呈现新页面,但我想避免为每个视图加载单独的页面。
物品控制器:
def index
@item = item.find(:all, :order => "id DESC")
end
def new
@item = item.new
end
def create
@item = item.new(params[:item])
if @item.save
redirect_to root_path
else
render "new"
end
end
def edit
@item = item.find(params[:id])
end
def update
@item = item.find(params[:id])
if @item.update_attributes(params[:item])
redirect_to root_path
else
render "index"
end
end
HTML:
<div id="left" ">
<p id=link_to "Current_Item", item_path %></p>
<p id=Link_to "Add_Item", new_item_path %></p>
<p id=Link_to "Edit_Item", edit_item_path %></p>
</div>
<div id="right">
</div>
路线文件:
resources :items