私の新しいモデルで、クライアントモデルから作成されたクライアントのリストをJobsという名前で使用しようとしています。データベース内の既存のエントリを更新していません
基本的には、ユーザーは、現在1つのクライアントに割り当てられているジョブのリストを表示してから、詳細情報を掘り下げることができます。
私は私の仕事のデータベースのclient_idと呼ばれ、しかし
<%= f.label :client_id %><br />
<%= f.collection_select :client_id, @clients, :id, :name, :prompt =>
"Select" %>
すべてのクライアントのドロップダウンリストを見ることができるように私の_form
ビューに次のコードを挿入しているに新しい列を挿入しました。私が提出したヒットは、私のリソースルートに従ってjobs/new
にPOSTしようとします。存在しません。
データベースにダミーデータを挿入しましたが、編集しようとするとうまく表示されます。 saveを押すとレコードに何も行われません。
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0ZVYpM9vTgY+BI55Y9yJDwCJwrwSgGL9xjHq8dz5OBE=", "job"=>{"name"=>"Sample Monthly", "client_id"=>"2", "frequency"=>"Monthly", "owner"=>"Me"}, "commit"=>"Save Job", "id"=>"1"}
Job Load (0.3ms) SELECT "jobs".* FROM "jobs" WHERE "jobs"."id" = ? LIMIT 1 [["id", "1"]]
(0.1ms) begin transaction
(0.5ms) UPDATE "jobs" SET "name" = 'Sample Monthly', "frequency" = 'Monthly', "updated_at" = '2012-05-12 17:04:23.818967' WHERE "jobs"."id" = 1
(108.3ms) commit transaction
Redirected to http://localhost:3000/jobs/1
ここに私のコントローラだ...
class JobsController < ApplicationController
before_filter :load_clients, :only => [ :new, :create, :edit ]
def index
@job = Job.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @job }
end
end
def new
@job = Job.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @Job }
end
end
def create
@job = Job.new(params[:job])
respond_to do |format|
if @job.save
format.html { redirect_to @job, notice: 'Job was successfully created.' }
format.json { render json: @job, status: :created, location: @job }
else
format.html { render action: "new" }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
def show
@job = Job.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @job }
end
end
def update
@job = Job.find(params[:id])
respond_to do |format|
if @job.update_attributes(params[:job])
format.html { redirect_to @job, notice: 'Job was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
private
def load_clients
@client = Client.find(:all)
end
end
私はこの作業を取得すると仮定は、比較的容易に修正ですが、これは私のフォーストのRailsアプリですし、私が開始する場所がわからないんだけど。
編集:
必要に応じて。ここに私の仕事のフォームがあります:
Edit2:私の仕事のモデルです。
class Job < ActiveRecord::Base
belongs_to :clients
end
あなたのフォームの詳細が必要です – Suborx
私の仕事_formを最初の投稿に追加しました – Keva161
あなたの質問をJobモデルのソースコードで更新できますか? attr_accessibleを使用していますか? – cutalion