有无论如何,我可以修改默认“显示”的行为?Rails - 修改/复制默认“显示”
目前,当用户点击一个按钮的主要场所
<%= link_to "ADD TO CART", product, {:class => "btn btn-primary", :target => '_blank', :method => "get"} %>
用户将被自动重定向到一个页面相应的信息。
现在我正在尝试创建一个稍微不同的页面(移动设备友好),并创建了一个可直接访问它的mobile_show页面。
我的问题是,我应该如何修改link_to以便它指向/mobile/products/id
而不是当前的products/id
?
更新(额外的信息):
在products_controller.rb`
# GET /mobile
# GET /mobile.json
def mobile
@products = Product.current
respond_to do |format|
format.html # mobile.html.erb
#format.json { render json: @products }
end
end`
# GET /mobile/products/1
# GET /mobile/products/1.json
def mobile_show
@product = Product.find(params[:id])
@product.update_attribute(:is_active, false)
respond_to do |format|
format.html # mobile_show.html.erb
#format.json { render json: @product }
end
end
在routes.rb中
match '/mobile' => 'products#mobile'
match '/cashback' => 'products#cashback'
match '/mobile/products/:id' => 'products#mobile_show'
P/S:我很新的轨道和网络 - 一般开发
,实际上取决于你的路线。你是如何添加对'/ mobile'命名空间的支持的? – jvnill 2013-03-05 06:41:40
@jvnill不太确定你的意思,但我更新了主帖。 – rlhh 2013-03-05 06:48:19