如何实现有3个固定categoris jobpost功能 [英] how to implement jobpost functionality that has 3 fixed categoris

查看:289
本文介绍了如何实现有3个固定categoris jobpost功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是创建一个将用于张贴3个固定类职位安置模式,即实习,企业和freelance.There将放置一个菜单,将有3个menues作为实习,企业和自由职业者和基于用户选择,对于这些3类相同的工作职位表将显示为创造就业岗位。
虽然显示jobposts不同势视图将基于分类显示。

What i want to do is create placement model which will be used to post jobs for 3 fixed categories i.e internship,corporate and freelance.There will be a menu of placement which will have 3 menues as internship,corporate and freelance and based on user selection ,for these 3 categories same job post form will be shown for creating job posts. While showing jobposts diffrent view will be shown based on category.

我没有得到我应该如何实现this.Whether我应该创建布局和类别,不同的模式,给协会评为了,许多类别此类别中安置和安置的belongsTo,但如果我这样做的方式,在类别模型我有3个固定的选择,我不会接受来自用户的选择,所以,我怎么可以添加在其中将其固定模型这3个选择,并添加jobposts他们categorywise?

I am not getting how i should implement this.Whether i should create placement and categories as a different model and give association as has-many categories in placement and belongsto placement in category, but if i do that way,in categories model i have 3 fixed choices and i am not going to accept that choice from user,so how can i add these 3 choices in the model which will be fixed and add jobposts for them categorywise?

我怎样才能实现这个位置的事情吗?

How can i implement this placement thing?

推荐答案

定义模型作为

Class Jobpost
  belongs_to :resource, :polymorphic => true, :dependent => :destroy
  accepts_nested_attributes_for :resource
  def resource_attributes=(params = {})
    self.resource = spec_type.constantize.new unless self.resource
    self.resource.attributes = params.select{|k| self.resource.attribute_names.include?(k) || self.resource.class::ACCESSOR.include?(k.to_sym)}
   end
end

class Freelancer
  has_one :jobpost, :as => :resource
end

将字段添加到Jobpost以创建字段(RESOURCE_ID:整数,RESOURCE_TYPE:字符串)

Add fields to Jobpost as to create fields(resource_id: integer, resource_type: string)

#jobposts table
t.references :resource, :polymorphic => true 

= form_for(@jobpost, :url => jobposts_path, :method => :post) do |f|
   = fields of Jobpost
   = f.fields_for :resource, build_resource('freelancer') do |freelancer|
     = fields of Freelancer

该Jobpost助手为

The Jobpost helper as

module JobpostsHelper
  def build_resource(klass)
    klass  = "{klass.capitalize}"
    object = eval("#{klass}.new")
    if @jobpost.resource.class.name == klass
      object = @jobpost.resource
    end
    return object
  end
end

使用javascript来显示子类别(自由职业者等)的领域被点击的链接,自由职业者的时候。当提交表单时,所有提交的所有子类别的领域,但它们在resource_attributes ='方法过滤掉了。

Use javascript to show the fields of subcategory(freelancer, etc) when the link for Freelancer is clicked. when the form is submitted, all the fields for all the subcategories are submitted but they are filtered out in the 'resource_attributes=' method.

这篇关于如何实现有3个固定categoris jobpost功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆