【发布时间】:2015-05-30 05:16:51
【问题描述】:
如何在仍然能够从控制器和模型中获取用户信息的同时创建单独的页面?
例如,我希望有单独的页面,但仍使用来自产品控制器的相同信息。
views/product/order.html.erb
然而,当我添加一个 simple_form_for 时,我得到一个错误
<%= simple_form_for(@products) do |f| %>
基本上我想要的只是一个单独的页面来提交产品信息。如果不是,我很乐意在同一个页面中执行此操作,并拥有像这样的旋转 simple_form,而无需创建多个页面。
http://malsup.com/jquery/cycle/
例子:
products_controller.rb
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
def index
@products = Product.where(availability: true)
respond_with(@products)
end
def show
end
def new
@product = Product.new
end
def edit
authorize! :manage, @product
end
def create
@product = current_user.products.new(product_params)
@product.save
respond_with(@product)
end
def update
authorize! :manage, @product
respond_to do |format|
if @product.update(product_params)
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
format.json { render :show, status: :ok, location: @product }
else
format.html { render :edit }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
def destroy
authorize! :manage, @product
@product.destroy
respond_to do |format|
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
format.json { head :no_content }
end
end
【问题讨论】:
-
粘贴你的控制器代码
-
你确定它的
@products在<%= simple_form_for(@products) do |f| %>中吗?
标签: jquery ruby-on-rails ruby