According to http://guides.rubyonrails.org/layouts_and_rendering.html
I should be able to define the path from a different controller as I have done in my create action in my micropostscontroller:
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
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 render 'static_pages/profile' to redirect_to profile_path the redirect works. Why is the browser ignoring the render request and going to the microposts controller home?
Additionally, the rendered microposts page gives a NoMethodError:
NoMethodError in Microposts#create
undefined method `name' for nil:NilClass
<% provide(:title, @user.name) %>
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'
The profile renders fine on its own when when redirected to, as @user is defined in profile action in the static_pages controller. @user = User.find_by_remember_token(cookies[:remember_token])