On 10 February 2017 at 13:46, 'krfg' via Ruby on Rails: Talk
<rubyonrails-talk@googlegroups.com> wrote:
> ...
> The home page is controlled by static_pages_controller.rb
> However the part of the home page concerning microposts creation and
> deletion is controlled by the microposts controller.
> Below is an extract of microposts_controller.rb
>
> class MicropostsController < ApplicationController
> before_action :logged_in_user, only: [:create, :destroy]
> before_action :correct_user, only: :destroy
>
> def create
> @micropost = current_user.microposts.build(micropost_params)
> if @micropost.save
> flash[:success] = "Micropost created!"
> redirect_to root_url
> else
> @feed_items = []
> render 'static_pages/home'
The render line does not invoke the static_pages controller, it just
invokes the view files for static_pages/home, so it will not call the
static_pages controller to setup your variables. I don't know how your
debug got to that code, I suspect it was from a different part of the
test. Perhaps you meant redirect_to which will invoke the controller
to perform the action. You may find this useful -
http://tosbourn.com/difference-between-redirect-render-rails/
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvwCY1JbnyK1dwqHRbUcTR7g38edBxB5TnuE_bMH-uf1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment