I recently moved over to Cloud 9 from Nitrous and have been really like it… but I’m a bit confused because things that worked on Nitrous are not working here… I don’t know if it’s a setting or if I need to do something different…
I am teaching myself… and until today, have been feeling pretty good about it… I ran into an issue I can’t seem to crack and am hoping for a little guidance. I am practicing by creating a blog. I have the routes and views set up - and the code will write to the database - but the redirect_to doesn’t seem to be working properly.
By navigating to: …/article/new, the user can enter a new article. Upon successful submission, the app should redirect to the URL …/article/id, display the article on show.html.erb and flash a message that the article saved successfully.
For some reason, I cannot get the URL redirect portion to work. The article saves, the show.html.erb displays with the proper message… but the url stays …/article/new. If the redirect doesn’t work, the rest of the application won’t work because other actions require different URLs (…/article/id/edit, for example).
I have been using
<%= @article.inspect %>
on the show page and it looks like everything has saved correctly (which I suspected because it calls the correct view).
Any thoughts would be very, very welcome. I’m really excited to be learning Ruby and Rails and look forward to getting through this.
class ArticlesController < ApplicationController def new @article = Article.new end def create @article = Article.new(article_params) if @article.save flash[:notice] = "Article was successfully created" redirect_to article_path(@article) else render 'new' end end def show @article = Article.find(params[:id]) end private def article_params params.require(:article).permit(:title, :description) end end
Prefix Verb URI Pattern Controller#Action root GET / pages#home about GET /about(.:format) pages#about articles GET /articles(.:format) articles#index POST /articles(.:format) articles#create new_article GET /articles/new(.:format) articles#new edit_article GET /articles/:id/edit(.:format) articles#edit article GET /articles/:id(.:format) articles#show PATCH /articles/:id(.:format) articles#update PUT /articles/:id(.:format) articles#update DELETE /articles/:id(.:format) articles#destroy