I am following this tutorial http://guides.rubyonrails.org/v3.2.13/getting_started.html to build my rails app in version 3.2.13 . If you go to the section 6.9 you will find controller and view for creating new posts . Here I do not get how @post
variable is passed from new
action to create
action and where is create
function called ? Also , I faced the same problem while working on edit
and update actions
. Please guide me through this .
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- How to dynamically load partial view Via jquery aj
- How to specify memcache server to Rack::Session::M
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
It's not passed to
create
action, it's instantiated again with params you pass from the form displayed withnew
action.create
action is called with POST request to the path specified in config/routes.rb, leading to specific controller and action.@post
is not passed fromnew
tocreate
theparams
hash is passed into the create method@post
is then set using thenew
method of the model not the controller.create
callsnew
and thensave
and returns the object.new
returns the object without saving and thensave
returns the validity of the object. That is why the create method in the controller callsnew
and then has a conditional statement forsave
. It is basically saying initialize this object then if it is a valid object do one thing if it is not do another. The create action is not called because of this check.The last line is unnecessarily redundant and thus why the example uses
new
followed bysave
.create
method for a Model is more succinct but probably best to use when you know the object is valid.Hope this gives you a better understanding but if you are still confused please let me know and I will try to explain further.