我尝试更新帖子,它告诉我“目标语言已成功更新”但实际上只要我点击更新按钮,帖子就会恢复原状。我在日志中找不到任何错误消息,任何人都可以帮助我吗?
运行rake路线时的结果
project_target_langs GET /projects/:project_id/target_langs(.:format) target_langs#index
POST /projects/:project_id/target_langs(.:format) target_langs#create
new_project_target_lang GET /projects/:project_id/target_langs/new(.:format) target_langs#new
edit_project_target_lang GET /projects/:project_id/target_langs/:id/edit(.:format) target_langs#edit
project_target_lang GET /projects/:project_id/target_langs/:id(.:format) target_langs#show
PUT /projects/:project_id/target_langs/:id(.:format) target_langs#update
DELETE /projects/:project_id/target_langs/:id(.:format) target_langs#destroy
POST /projects/:project_id/target_langs/:id(.:format) target_langs#update
我的控制器代码
def update
@project = Project.find(params[:project_id])
@targetLang = @project.targetLangs.find(params[:id])
respond_to do |format|
if @targetLang.update_attributes(params[:targetLang])
format.html { redirect_to project_path(@project), notice: 'Target language was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
Show.erb
<% @project.targetLangs.each do |targetLang| %>
<%= form_for([targetLang.project, targetLang]) do |f| %>
<%= f.text_field :language, :class => 'textbox1' %>
<%= f.text_field :status, :class => 'textbox1' %>
<%= f.text_area :notes, :size => "30x2", :class => 'textbox1' %>
<%= link_to 'Remove', [targetLang.project, targetLang],
:data => {:confirm => 'Confirm deletion!'},
:method => :delete %>
<%= link_to 'Update', [targetLang.project, targetLang],
:method => :update %>
的routes.rb
Dashboard::Application.routes.draw do
resources :projects do
resources :target_langs
match '/target_langs/:id' => 'target_langs#update', :via => :post
end
我的日志
Started POST "/projects/5/target_langs/14" for 127.0.0.1 at 2012-07-31 10:14:58 -0400
Processing by TargetLangsController#update as HTML
Parameters: {"authenticity_token"=>"kTkBzwah/MylU9N96i+s5lu99PskX28XF0eK1THsHLY=", "project_id"=>"5", "id"=>"14"}
←[1m←[35mProject Load (0.0ms)←[0m SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT 1 [["id", "5"]]
←[1m←[36mTargetLang Load (0.0ms)←[0m ←[1mSELECT "target_langs".* FROM "target_langs" WHERE "target_langs"."project_id" = 5 AND "target_langs"."id"
= ? LIMIT 1←[0m [["id", "14"]]
←[1m←[35m (0.0ms)←[0m begin transaction
←[1m←[36m (0.0ms)←[0m ←[1mcommit transaction←[0m
Redirected to http://localhost:3000/projects/5
Completed 302 Found in 125ms (ActiveRecord: 0.0ms)
Started GET "/projects/5" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Processing by ProjectsController#show as HTML
Parameters: {"id"=>"5"}
←[1m←[35mProject Load (0.0ms)←[0m SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT 1 [["id", "5"]]
←[1m←[36mTargetLang Load (0.0ms)←[0m ←[1mSELECT "target_langs".* FROM "target_langs" WHERE "target_langs"."project_id" = 5←[0m
←[1m←[35mProject Load (0.0ms)←[0m SELECT "projects".* FROM "projects" WHERE "projects"."id" = 5 LIMIT 1
←[1m←[36mCACHE (0.0ms)←[0m ←[1mSELECT "projects".* FROM "projects" WHERE "projects"."id" = 5 LIMIT 1←[0m
←[1m←[35mCACHE (0.0ms)←[0m SELECT "projects".* FROM "projects" WHERE "projects"."id" = 5 LIMIT 1
←[1m←[36mCACHE (0.0ms)←[0m ←[1mSELECT "projects".* FROM "projects" WHERE "projects"."id" = 5 LIMIT 1←[0m
←[1m←[35mCACHE (0.0ms)←[0m SELECT "projects".* FROM "projects" WHERE "projects"."id" = 5 LIMIT 1
Rendered projects/show.html.erb within layouts/application (46.9ms)
Rendered layouts/_shim.html.erb (0.0ms)
Rendered layouts/_header.html.erb (0.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 94ms (Views: 93.8ms | ActiveRecord: 0.0ms)
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /custom.css - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/projects.css?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /projects.css - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /application.css - 304 Not Modified (31ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /scaffolds.css - 304 Not Modified (15ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/target_langs.css?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /target_langs.css - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /jquery.js - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/projects.js?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /projects.js - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/target_langs.js?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /target_langs.js - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /application.js - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/telelingua.gif" for 127.0.0.1 at 2012-07-31 10:14:59 -0400
Served asset /telelingua.gif - 304 Not Modified (0ms)
[2012-07-31 10:14:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
答案 0 :(得分:0)
我认为这里存在一个简单的问题。
你有两个链接,一个到:删除(我猜这是有效的),另一个是:更新(不起作用)
简单地说,在HTML中,<a>
标记(link_to
返回的内容)不会提交表单。
在示例中单击“更新”时,您发送的唯一参数是id。
相反,你应该说submit_tag("Update")
这将提交表格,一切都应该很好。