Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将链接_更改为具有模态_Ruby On Rails_Bootstrap Modal_Link To_Simple Form For - Fatal编程技术网

Ruby on rails 将链接_更改为具有模态

Ruby on rails 将链接_更改为具有模态,ruby-on-rails,bootstrap-modal,link-to,simple-form-for,Ruby On Rails,Bootstrap Modal,Link To,Simple Form For,我正在做一个项目,在这个项目中,人们可以被雇来参加一个活动。 实际上,他们只能“假设”,但我不想添加这样一个选项,即他们可以在应用程序中添加价格 这是我的古老密码[工作]: <% if @current_user != @project.user %> <% if project_job.users.find { |user| user == current_user } %> <%= link_to "Retirer ma candidature

我正在做一个项目,在这个项目中,人们可以被雇来参加一个活动。 实际上,他们只能“假设”,但我不想添加这样一个选项,即他们可以在应用程序中添加价格

这是我的古老密码[工作]:

<% if @current_user != @project.user %>
    <% if project_job.users.find { |user| user == current_user } %>
     <%= link_to "Retirer ma candidature", project_project_job_postulant_path(@project, project_job, project_job.postulants.find_by_user_id(current_user.id)), method: :delete, class:"btn btn-primary btn-prostate" %>
    <% else %>
     <%= link_to "Postuler", project_project_job_postulants_path(@project, project_job), method: :post, class:"btn btn-primary btn-prostate" %>
    <% end %>
  <% end %>
路线:

    Rails.application.routes.draw do
      get 'project_jobs/Postulants'
      root to: 'pages#home'
      get '/about', to: 'pages#about'
      get '/manager', to: 'pages#manager'

      devise_for :users, controllers: { registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks' }
      # , controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
      resources :users, only: [ :edit, :update, :show, :manager ] do
        resources :skills, only: [ :edit, :create, :show, :destroy ]
      end

      resources :projects , only: [:new, :create, :show, :edit, :destroy, :update, :index] do
        resources :project_jobs , only: [:show, :create, :destroy, :index, :new ] do
          resources :postulants , only: [:show, :destroy, :index, :create]
        end
      end

      post 'projects/:project_id/postulants/:id/accepted', to: 'postulants#accepted', as: 'accepted'
      post 'projects/:project_id/postulants/:id/rejected', to: 'postulants#rejected', as: 'rejected'
      post 'projects/:id/publish', to: 'projects#publish', as: 'publish'


    end
模型项目工作

class ProjectJob < ActiveRecord::Base
  belongs_to :project
  belongs_to :job

  has_many :postulants, dependent: :destroy
  has_many :users, through: :postulants

  validates :project_id, presence: true
  validates :number, :numericality => { :greater_than => 0 }
  validates :job, presence: true
end
class ProjectJob{:大于=>0}
验证:作业,状态:true
结束
模型姿态

    class Postulant < ActiveRecord::Base
      belongs_to :project_job
      belongs_to :user

      validates :user_id, presence: true, uniqueness: { scope: :project_job,
        message: "You already apply to this job" }

    end
class postatant
假设政策

    class PostulantPolicy < ApplicationPolicy
      class Scope < Scope
        def resolve
          scope
        end
      end

      def create?
        true
      end


      def destroy?
        record.user == user
      end

      def accepted?
        true
      end

      def rejected?
        true
      end
    end
class-positionPolicy
姿态控制器

    class PostulantsController < ApplicationController
      before_action :set_project_job, only: [ :create ]


      def create
        @postulant = @project_job.postulants.build(postulant_params)
        authorize @postulant
        @postulant.save
        redirect_to project_path(@project_job.project)
      end

      def destroy
        @postulant = Postulant.find(params[:id])
        authorize @postulant
        @postulant.destroy
        redirect_to project_path(@postulant.project_job.project)
      end

      def new

      end

      def accepted
        @postulant = Postulant.find(params[:id])
        @postulant.status = true
        @postulant.save
        authorize @postulant
        @project_job = @postulant.project_job
        @project_job.number -= 1
        @project_job.save
        redirect_to :back
      end

      def rejected
        @postulant = Postulant.find(params[:id])
        @postulant.status = false
        @postulant.save
        authorize @postulant
        redirect_to :back
      end


      private

      def set_project_job
        @project_job = ProjectJob.find(params[:project_job_id])
      end


      def postulant_params
        params.require(:postulant).permit(:project_jobs_id, :user_id, :budget)
      end

    end
class positionsController
尝试将表单更改为-

<%= simple_form_for [@project, project_job, project_job.postulants.build] do |f| %>
 <%= f.hidden_field :user_id, current_user.id %>
 <%= f.input :budget, required: true, autofocus: true, placeholder: "Budget moyen par personne. En Euros - €"%>
 <%= f.button :submit, value: "Add", class: "btn btn-primary" %>
<% end %>

尝试将表单更改为-

<%= simple_form_for [@project, project_job, project_job.postulants.build] do |f| %>
 <%= f.hidden_field :user_id, current_user.id %>
 <%= f.input :budget, required: true, autofocus: true, placeholder: "Budget moyen par personne. En Euros - €"%>
 <%= f.button :submit, value: "Add", class: "btn btn-primary" %>
<% end %>


当您将
和您的routes.rb更改为
simple\u form\u时,您能发布您遇到的错误吗?您还需要其他信息吗?
price
是哪个表的一列?当您在加载表单期间或提交表单后遇到错误时?另外,您可以显示完整的错误日志吗?我只需添加终端错误并尝试更改:price with:budget,这也是一列postulant。提交表单后出现错误。我不能尝试使用我的旧表单和工作表单吗?您可以发布更改为
simple\u form\u for
和routes.rb时遇到的错误吗?您还需要其他信息吗?
price
是哪个表的一列?当您在加载表单期间或提交表单后遇到错误时?另外,您可以显示完整的错误日志吗?我只需添加终端错误并尝试更改:price with:budget,这也是一列postulant。提交表单后出现错误。我不能尝试使用旧的和正在工作的
<%= simple_form_for [@project, project_job, project_job.postulants.build] do |f| %>
 <%= f.hidden_field :user_id, current_user.id %>
 <%= f.input :budget, required: true, autofocus: true, placeholder: "Budget moyen par personne. En Euros - €"%>
 <%= f.button :submit, value: "Add", class: "btn btn-primary" %>
<% end %>