Patrick.SE
Patrick.SE

Reputation: 4564

Url changes when rendering view

I'm following the Ruby getting started guide, section 5.10 asks us to add code to check if the data added to the model is valid, if it isn't then we should call render 'new' to refresh the page with the users data:

def create
@article = Article.new(article_params)
  if @article.save
    redirect_to @article
  else
    render 'new'
  end
end

I've noticed though that the moment I submit wrong data my url changes from :

http://localhost:3000/articles/new to http://localhost:3000/articles, why is that? The rendering seems to work since I get the error messages indicating my invalid input just like in the tutorial.

The html output looks slightly off too, there's an extra space between one of the labels and the text input field.

Upvotes: 0

Views: 43

Answers (1)

Enrique Vargas Acha
Enrique Vargas Acha

Reputation: 1

URL change because it's a PUT HTTP method, RoR use REST for CRUD actions, "In Rails, a resourceful route provides a mapping between HTTP verbs and URLs to controller actions. By convention, each action also maps to particular CRUD operations in a database."

Upvotes: 0

Related Questions