Note that there are some explanatory texts on larger screens.

plurals
  1. POPath defined in controller and action is getting ignored, Ruby on Rails
    primarykey
    data
    text
    <p>According to <a href="http://guides.rubyonrails.org/layouts_and_rendering.html" rel="nofollow">http://guides.rubyonrails.org/layouts_and_rendering.html</a></p> <p>I should be able to define the path from a different controller as I have done in my create action in my micropostscontroller:</p> <pre><code>def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "Micropost created!" redirect_to profile_path else render 'static_pages/profile' end end </code></pre> <p>When I unsuccessfully create a post, however (leave it blank or make it too long), the page '/microposts' is rendered, the nonexistent home page of the controller. When I successfully create a micropost I am redirected to the profile path '/profile', and when I've changed <code>render 'static_pages/profile'</code> to <code>redirect_to profile_path</code> the redirect works. Why is the browser ignoring the render request and going to the microposts controller home?</p> <p>Additionally, the rendered microposts page gives a NoMethodError:</p> <pre><code>NoMethodError in Microposts#create undefined method `name' for nil:NilClass &lt;% provide(:title, @user.name) %&gt; app/views/static_pages/profile.html.erb:16:in `_app_views_static_pages_profile_html_erb___1610169404003779010_70327969935820' app/controllers/microposts_controller.rb:10:in `create' </code></pre> <p>The profile renders fine on its own when when redirected to, as @user is defined in profile action in the static_pages controller. <code>@user = User.find_by_remember_token(cookies[:remember_token])</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload