I can't update my rails form

HXH

I am a rails beginner,now I follow the guide and create a test project as below:

admin_controller.rb

def blogEdit
  @btnName = "更新"
  @submitURL = "blogUpdate"
  @blog=Blog.find(params[:id])
end

def blogUpdate
  @blog=Blog.find(params[:id])
  @blog.update(params[:blog])
  redirect_to "/admin/blogList"
end

blogEdit.slim

= render "blogForm"  

_blogForm.slim

=form_for :blog,url:{action: @submitURL} do |f|
=f.label  :title ,"标题"
=f.text_field :title 
=f.label  :body ,"内容"
=f.text_area :body,rows:10,style:'width:500px;'
=f.label  :author ,"作者"
=f.text_field :author
=f.hidden_field :id
=f.submit @btnName,class:'btn' 

but when I update a blog,I get the error:

Couldn't find Blog without an ID
Rails.root: /home/hxh/share/ruby/myblog

Application Trace | Framework Trace | Full Trace
app/controllers/admin_controller.rb:28:in `blogUpdate'

Request

Parameters:

{"utf8"=>"✓",
  "authenticity_token"=>"3SBp+xSft8SzA5poczxNSU1zKReO2OpZQqgESn6ZURs=",
   "blog"=>{"title"=>"违法的",
   "body"=>"的说法都是",
   "author"=>"似懂非懂",
   "id"=>"2"},

"commit"=>"更新"}

so It shows that I not get the params[:id]

@blog=Blog.find(params[:id])

I had follow the guide,why I got the result?

ck3g

You're passing =f.hidden_field :id into form. So your id in in params[:blog][:id]. But id have to be passing via @submitURL. Judging by your params @submitUrl aren't contains id of the blog.

You are not following guide convensions or your guide doesn't do it. Because there is common rules for name actions. It's edit and update instead your blogEdit and blogUpdate.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

I can't put my Login Form in the correct place

분류에서Dev

Can't get Update_all in a form full of check_box_tag fields to work at all in Rails 4

분류에서Dev

I can't display my table (codeigniter)

분류에서Dev

I can't exit my local network

분류에서Dev

Can't submit my form using anchor instead of button

분류에서Dev

How can I change my number validation from a form to a prompt?

분류에서Dev

Can't login to my Ubuntu 14.04 after system update

분류에서Dev

Why can't Excel update some of the links in my workbook

분류에서Dev

How can I sync my data from an external database in Rails?

분류에서Dev

I can't get the html form to run a php script

분류에서Dev

Tried to install a .deb and now I can't update or install anything

분류에서Dev

Rails: after using scaffold, I can't migrate

분류에서Dev

I set my AWS keys and they show up in linux terminal, but Rails 4 app can't find them. Using aws-sdk and carrierwave-aws gems

분류에서Dev

I can fetch my entities that I save only on the first launch. If I relaunch the app, I can't fetch my entities

분류에서Dev

Why can't I crash my system with a fork bomb?

분류에서Dev

Why can't I spoof Facebook with my own DNS server?

분류에서Dev

Why can't I restart my maia service?

분류에서Dev

Why can't I create a new Thread with an instance of my class?

분류에서Dev

I can't show AdMob banner in my application

분류에서Dev

I can't call variables from my other page PHP

분류에서Dev

Why can't I compile USB Proxy on my Beaglebone?

분류에서Dev

Why can't I access my objects member variable?

분류에서Dev

I can't run my mobile app on worklight development server

분류에서Dev

I can't get my UITableView to reload data in swift

분류에서Dev

I can't get an answer out of my C++ program

분류에서Dev

I can't get my Wacom Intuos to work in Ubuntu at all

분류에서Dev

Can't update to 20.10

분류에서Dev

I mess up installing my Ubuntu and now i can't boot my windows

분류에서Dev

Why my form action in modal is not update?

Related 관련 기사

  1. 1

    I can't put my Login Form in the correct place

  2. 2

    Can't get Update_all in a form full of check_box_tag fields to work at all in Rails 4

  3. 3

    I can't display my table (codeigniter)

  4. 4

    I can't exit my local network

  5. 5

    Can't submit my form using anchor instead of button

  6. 6

    How can I change my number validation from a form to a prompt?

  7. 7

    Can't login to my Ubuntu 14.04 after system update

  8. 8

    Why can't Excel update some of the links in my workbook

  9. 9

    How can I sync my data from an external database in Rails?

  10. 10

    I can't get the html form to run a php script

  11. 11

    Tried to install a .deb and now I can't update or install anything

  12. 12

    Rails: after using scaffold, I can't migrate

  13. 13

    I set my AWS keys and they show up in linux terminal, but Rails 4 app can't find them. Using aws-sdk and carrierwave-aws gems

  14. 14

    I can fetch my entities that I save only on the first launch. If I relaunch the app, I can't fetch my entities

  15. 15

    Why can't I crash my system with a fork bomb?

  16. 16

    Why can't I spoof Facebook with my own DNS server?

  17. 17

    Why can't I restart my maia service?

  18. 18

    Why can't I create a new Thread with an instance of my class?

  19. 19

    I can't show AdMob banner in my application

  20. 20

    I can't call variables from my other page PHP

  21. 21

    Why can't I compile USB Proxy on my Beaglebone?

  22. 22

    Why can't I access my objects member variable?

  23. 23

    I can't run my mobile app on worklight development server

  24. 24

    I can't get my UITableView to reload data in swift

  25. 25

    I can't get an answer out of my C++ program

  26. 26

    I can't get my Wacom Intuos to work in Ubuntu at all

  27. 27

    Can't update to 20.10

  28. 28

    I mess up installing my Ubuntu and now i can't boot my windows

  29. 29

    Why my form action in modal is not update?

뜨겁다태그

보관