我正在开发一种工作板,在那里我有一个名为'jobdetails'的工作细节('jobdetails'显示开口资源)的工作与应用按钮,应该重定向到'jobapplications'“页面”,求职者可以上传他的cv(尚未实现)并保存opens_id。如何将URL中的参数传递给rails中的另一个资源?
我尝试了很多方法,但仍然无法正常工作。
我说我想通过参数传递的网址,但我用其他方式,模型或控制器打开。
谢谢。
编辑:我能保存记录,但opening_id仍为空白......
Rails.application.routes.draw do
resources :posts
devise_for :jobseekers, controllers: { registrations: "jobseekers/registrations", sessions: "jobseekers/sessions" }
resources :companypics
devise_for :users, controllers: { registrations: "registrations" }
resources :openings
resources :jobapplications
resources :companies
resources :locations
resources :timesheets
resources :expenses
resources :jobdescriptions
resources :jobdetails
root :to => 'dashbords#index'
end
class JobapplicationsController < ApplicationController
before_filter :authenticate_jobseeker!
layout 'apply'
def applyparam
@opening = Opening.find(params[:opening])
end
def index
@jobapplications = Jobapplication.all
end
def show
end
def new
@jobapplication = Jobapplication.new
end
def edit
end
def create
@jobapplication = current_jobseeker.jobapplications.create(jobapplication_params)
@jobapplication.save
redirect_to new_jobapplication_path
end
def update
@jobapplication.update(jobapplication_params)
end
def destroy
@jobapplication.destroy
end
private
def jobapplication_params
params.require(:jobapplication).permit(:opening_id, :jobseeker_id,)
end
end
class JobdetailsController < ApplicationController
layout 'apply'
def show
@jobdetail = Opening.find_by_applyjobid(params[:applyjobid])
@logo = current_user.company.logo.url
end
end
Jobdetails Show
<div class='login-container'>
<div class='container'>
<div class='row'>
<div class='col-sm-4 col-sm-offset-4'>
<div class='container'>
<div class='.col-xs-6 .col-md-4'>
<div class='row'>
<h1>
<strong><%= @jobdetail.jobdescription.job_title %></strong>
</h1>
<br/>
<b>Company: </b>
<br/>
<%= @jobdetail.company.company_name %>
<br> </br>
<%= image_tag @logo %>
<br>
<b>Job Location: </b>
<br/>
<%= @jobdetail.location.name %> <%= @jobdetail.location.postalcode %>
<br>
<br/>
<b>Job salary: </b>
<br/>
<%= @jobdetail.jobdescription.rate_pay %>
<br>
<br/>
<p class="jobsummary"><b>Job Summary: </b>
<br/>
<%= @jobdetail.jobdescription.job_summary %></p>
<br>
<br/>
<% if [email protected]? -%>
<b>Job shift: </b>
<br/>
<%= @jobdetail.jobdescription.shift %>
<br>
<br/>
<% end %>
<br>
<b>Job requirements: </b>
<br/>
<% if [email protected]_duties.blank? -%>
<%= @jobdetail.jobdescription.job_duties %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.tasks %>
<br>
<br/>
<% end %>
<% if [email protected]_duties.blank? -%>
<%= @jobdetail.jobdescription.job_duties %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.responsibilities %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.results %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.skills %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.knowledge %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.abilities %>
<br>
<br/>
<% end %>
<br>
<b>Education: </b>
<br/>
<% if [email protected]_and_training.blank? -%>
<%= @jobdetail.jobdescription.education_and_training %>
<br>
<br/>
<% end %>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.qualifications %>
<br>
<br/>
<% end %>
<% if [email protected]_certification.blank? -%>
<%= @jobdetail.jobdescription.license_certification %>
<br>
<br/>
<% end %>
<br>
<b>Job environment: </b>
<br/>
<% if [email protected]_requirement.blank? -%>
<%= @jobdetail.jobdescription.physical_requirement %>
<br>
<br/>
<% end %>
<% if [email protected]_envir_condition.blank? -%>
<%= @jobdetail.jobdescription.work_envir_condition %>
<br>
<br/>
<% end %>
<% if [email protected]_clothing_and_devices_required.blank? -%>
<%= @jobdetail.jobdescription.protective_clothing_and_devices_required %>
<br>
<br/>
<% end %>
<% if [email protected]_or_equipment_required.blank? -%>
<%= @jobdetail.jobdescription.tools_or_equipment_required %>
<br>
<br/>
<% end %>
<br>
<b>Benefits: </b>
<br/>
<% if [email protected]? -%>
<%= @jobdetail.jobdescription.benefits %>
<br>
<br/>
<% end %>
<% if [email protected]_benefits.blank? -%>
<%= @jobdetail.jobdescription.other_benefits %>
<br>
<br/>
<% end %>
<br>
<br/>
<%= link_to "Apply now", new_jobapplication_path(:opening => @jobdetail.id) %>
<%= form_for (@jobapplication) do |f| %>
<div class='login-container'>
<div class='container'>
<div class='row'>
<div class='col-sm-4 col-sm-offset-4'>
<h1 class='text-center title'>Apply</h1>
<%= render 'layouts/messages' %>
<div class='form-group'>
</div>
</div>
<div class="form-group">
<%= f.hidden_field :opening %>
<%= f.submit "Submit", class: "btn btn-large btn-success" %>
<% end %>
</form>
class Jobapplication < ActiveRecord::Base
belongs_to :opening
end
create_table "jobapplications", force: true do |t|
t.integer "opening_id"
t.integer "jobseeker_id"
t.datetime "created_at"
t.datetime "updated_at"
end
Started POST "/jobapplications" for 127.0.0.1 at 2015-05-25 10:49:38 +0100
Processing by JobapplicationsController#create as HTML
Parameters: {"utf8"=>"V", "authenticity_token"=>"+0z1IIG0COeYZUQavPUZXu/5m316t9VrUs9eiOFrMjA=", "jobapplication"=>{"opening"=>"#<Opening:0x85cc
f80>"}, "commit"=>"Submit your timesheet"}
Jobseeker Load (1.0ms) SELECT "jobseekers".* FROM "jobseekers" WHERE "jobseekers"."id" = 1 ORDER BY "jobseekers"."id" ASC LIMIT 1
Unpermitted parameters: opening
(0.0ms) begin transaction
SQL (2.0ms) INSERT INTO "jobapplications" ("created_at", "jobseeker_id", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-05-25 09:49:39.
818752"], ["jobseeker_id", 1], ["updated_at", "2015-05-25 09:49:39.818752"]]
(131.0ms) commit transaction
(0.0ms) begin transaction
(0.0ms) commit transaction
Redirected to http://localhost:3000/jobapplications/new
Completed 302 Found in 591ms (ActiveRecord: 134.0ms)
您想在哪个操作中接收参数?并从哪里? –
嗨,从Jobdetails#显示到工作申请#新谢谢 – reme