0

How exactly do I create separate pages while still able to user info from controller and model?

For example, I want to have separate pages but still using the same info from the products controller.

views/product/order.html.erb

Yet when I add a simple_form_for I get an error

<%= simple_form_for(@products) do |f| %>

Basically all I'm trying to have is a separte page to submit info for the product. If not I'd gladly be happy to do it within the same page and have a revolving simple_form like this without having to create multiple pages.

http://malsup.com/jquery/cycle/

Example:

Example-1 Example-2 Example-3

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
2
  • paste your controller code Commented May 30, 2015 at 5:22
  • Are you sure its @products in <%= simple_form_for(@products) do |f| %>? Commented May 30, 2015 at 5:23

1 Answer 1

1
<%= simple_form_for(@product) do |f| %>

Use @product instead of @products

Add following to products_controller.rb

def order
  @product = Product.new
end
Sign up to request clarification or add additional context in comments.

4 Comments

I'm still getting undefined method model_name for nil:NilClass, I have updated an example in the question. How do I do that without having to create a new page, like allow the form to just slide by pressing the bubbles at the top?
where is your method order has defined in your products_controller?
I have not defined order, I just thought of a random page
Try resources :products in your congig/routes.rb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.