Javascript 显示嵌套窗体

Javascript 显示嵌套窗体,javascript,jquery,mysql,ruby-on-rails,ruby,Javascript,Jquery,Mysql,Ruby On Rails,Ruby,我想显示我的订单,就像上面显示的配料一样。我不明白为什么不是 帖子:成分嵌套 联机:订单嵌套 查看/发布/显示: <p> <strong>Title:</strong> <%= @post.title %> </p> <p> Posted by : <%= link_to @post.user.pseudo, profile_path(@post.user.pseudo) %>, <%= tim

我想显示我的订单,就像上面显示的配料一样。我不明白为什么不是

帖子:成分嵌套
联机:订单嵌套

查看/发布/显示:

<p>
  <strong>Title:</strong>
  <%= @post.title %>
</p>

<p> Posted by : <%= link_to @post.user.pseudo, profile_path(@post.user.pseudo) %>,  <%= time_ago_in_words(@post.created_at) %> ago </p>
<p>
  <strong>Image:</strong>
 <%= image_tag @post.image.url(:medium) %>
</p>

<p>
  <strong>Description:</strong>
  <%= @post.description %>
</p>


 <div class="btn-group" role="group" aria-label="...">
  <%= link_to '-  Pusher  - ', new_post_online_path(@post), data: { confirm: 'Confirmer la mise en ligne de #{@title}?' }, class: "btn btn-primary " %>


 <div class="col-md-12">
    <h3>Ingrédients :</h3>
    <div id="ingredients">

      <ul>
        <%- @post.ingredients.each do |ingredient| %>
        <li>
          <%= ingredient.name %>
        </li>
        <%end%>
      </ul>
    </div>
  </div>
<br>

  <div class="col-md-9">
    <h3>Parts :</h3>
    <div id="ingredients">

      <ul>
        <%- @post.onlines.orders.each do |order| %>
        <li>
          <%= order.id %>
        </li>
        <%end%>
      </ul>
    </div>
  </div>

  <%= link_to 'Patcher', edit_post_online_path(@post, @post.onlines.last), class: "btn btn-warning"%>



      </div>

标题:

邮寄人:,年月日

图像:

说明:

英格兰人:

部分:
岗位控制员:

class PostsController < ApplicationController
  before_action :authenticate_user!
  before_action :set_post, only: [:show, :edit, :update, :destroy]
  before_action :owned_post, only: [:edit, :update, :destroy]


  # GET /posts
  # GET /posts.json
  def index
        @posts = Post.push_posts 

end  


  # GET /posts/1
  # GET /posts/1.json
  def show

  end

  # GET /posts/new
  def new
    @post = current_user.posts.build
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = current_user.posts.build(post_params)
    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /posts/1
  # PATCH/PUT /posts/1.json
  def update
    respond_to do |format|
      if @post.update(post_params)
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { render :show, status: :ok, location: @post }
      else
        format.html { render :edit }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post.destroy
    respond_to do |format|
      format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
      format.json { head :no_content }
    end
  end



  private
    # Use callbacks to share common setup or constraints between actions.
    def set_post
      @post = Post.find(params[:id])
    end




    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:user_id, :title, :description, :image, ingredients_attributes: [:id, :name, :_destroy])
    end

    def owned_post  
  unless current_user == @post.user
    flash[:alert] = "That post doesn't belong to you!"
    redirect_to root_path
  end
end  

def set_online
  @onlines = Online.find_by(params[:id]) 
  end 

end
class OnlinesController < ApplicationController
  before_action :authenticate_user!
  before_action :set_post 
  before_action :owned_online, only: [:new, :update]
  before_action :set_online


  def new 
    @online = current_user.onlines.build
    @online.post_id = @post.id
    @online.user_id = current_user.id
  end 

  def edit
  end

   def taked 
    @online.orders.update(taked: false)
  end 

  def create 
      if Online.where(post_id: params[:post_id]).any?
      @online = Online.where(post_id: params[:post_id]).last.update_attributes(push: false)
      end
     @online = @post.onlines.create(online_params)
    if @online.save
      if @online.portion <= 0
          @online.update(push: false)
          flash[:success] = 'Veuillez indiquer le nombre de parts disponibles '
          redirect_to root_path 
        else
       @online.update(pushed_at: Time.zone.now)
       @online.update(push: true)


       flash[:success] = 'Votre post est en ligne !'
      redirect_to root_path

    end
    else 
      render 'new'
    end 
  end 




def update  
    if @onlines.update(online_params)
      if @online.push == false
        if @online.portion <= 0
          @online.update(push: false)
          flash[:success] = 'Veuillez indiquer le nombre de parts disponibles '
          redirect_to root_path 
        else
         @online.update(push: true)
         flash[:success] = 'Votre post a bien été pushé !'
         redirect_to root_path      
      end   
    end
    else
      @user.errors.full_messages
      flash[:error] = @user.errors.full_messages
      render :edit
    end
  end


private 

def online_params
  params.require(:online).permit(:user_id, :post_id, :prix, :portion, :push, :pushed_at, orders_attributes: [:id, :taked, :taked_at, :taked_by, :validated_at, :validated_by, :_destroy])
  end 

  def owned_online 
     @post = Post.find(params[:post_id])
  unless current_user == @post.user
    flash[:alert] = "That post doesn't belong to you!"
    redirect_to :back
  end
end  

  def set_post
  @post = Post.find_by(params[:post_id]) 
  end 


  def set_online
    @post = Post.find(params[:post_id])
    @online = Online.find_by(params[:id]) 
  end 

end
class PostsController
在线控制器:

class PostsController < ApplicationController
  before_action :authenticate_user!
  before_action :set_post, only: [:show, :edit, :update, :destroy]
  before_action :owned_post, only: [:edit, :update, :destroy]


  # GET /posts
  # GET /posts.json
  def index
        @posts = Post.push_posts 

end  


  # GET /posts/1
  # GET /posts/1.json
  def show

  end

  # GET /posts/new
  def new
    @post = current_user.posts.build
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = current_user.posts.build(post_params)
    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /posts/1
  # PATCH/PUT /posts/1.json
  def update
    respond_to do |format|
      if @post.update(post_params)
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { render :show, status: :ok, location: @post }
      else
        format.html { render :edit }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post.destroy
    respond_to do |format|
      format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
      format.json { head :no_content }
    end
  end



  private
    # Use callbacks to share common setup or constraints between actions.
    def set_post
      @post = Post.find(params[:id])
    end




    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:user_id, :title, :description, :image, ingredients_attributes: [:id, :name, :_destroy])
    end

    def owned_post  
  unless current_user == @post.user
    flash[:alert] = "That post doesn't belong to you!"
    redirect_to root_path
  end
end  

def set_online
  @onlines = Online.find_by(params[:id]) 
  end 

end
class OnlinesController < ApplicationController
  before_action :authenticate_user!
  before_action :set_post 
  before_action :owned_online, only: [:new, :update]
  before_action :set_online


  def new 
    @online = current_user.onlines.build
    @online.post_id = @post.id
    @online.user_id = current_user.id
  end 

  def edit
  end

   def taked 
    @online.orders.update(taked: false)
  end 

  def create 
      if Online.where(post_id: params[:post_id]).any?
      @online = Online.where(post_id: params[:post_id]).last.update_attributes(push: false)
      end
     @online = @post.onlines.create(online_params)
    if @online.save
      if @online.portion <= 0
          @online.update(push: false)
          flash[:success] = 'Veuillez indiquer le nombre de parts disponibles '
          redirect_to root_path 
        else
       @online.update(pushed_at: Time.zone.now)
       @online.update(push: true)


       flash[:success] = 'Votre post est en ligne !'
      redirect_to root_path

    end
    else 
      render 'new'
    end 
  end 




def update  
    if @onlines.update(online_params)
      if @online.push == false
        if @online.portion <= 0
          @online.update(push: false)
          flash[:success] = 'Veuillez indiquer le nombre de parts disponibles '
          redirect_to root_path 
        else
         @online.update(push: true)
         flash[:success] = 'Votre post a bien été pushé !'
         redirect_to root_path      
      end   
    end
    else
      @user.errors.full_messages
      flash[:error] = @user.errors.full_messages
      render :edit
    end
  end


private 

def online_params
  params.require(:online).permit(:user_id, :post_id, :prix, :portion, :push, :pushed_at, orders_attributes: [:id, :taked, :taked_at, :taked_by, :validated_at, :validated_by, :_destroy])
  end 

  def owned_online 
     @post = Post.find(params[:post_id])
  unless current_user == @post.user
    flash[:alert] = "That post doesn't belong to you!"
    redirect_to :back
  end
end  

  def set_post
  @post = Post.find_by(params[:post_id]) 
  end 


  def set_online
    @post = Post.find(params[:post_id])
    @online = Online.find_by(params[:id]) 
  end 

end
class OnlinesController如果@online.partment你的
帖子有很多
在线
s。每个
在线
都有许多
订单
。所以,你应该在你的文章中重复每一个在线的顺序

  <ul>
    <%- @post.onlines.each do |online| %>
      <%- online.orders.each do |order| %>
      <li>
        <%= order.id %>
      </li>
      <%end%>
    <%end%>
  </ul>

大纲
和订单
之间的关联是什么?订单是一种嵌套的在线形式,我把我的模型放上去很棒!这正是我所需要的,你自己出去早就应该了