|
This is actually the view that serves as the home page view, when a user is not logged in. We use the form_for helper method to create a form and pass it the @user variable as a parameter. Then, inside the form (which is inside the Ruby block), we first print out errors. Of course, there won’t be any errors on the page the first time around.
However, any input that fails our validation rules results in an error message that is displayed in a list item.
Then, we have the fields for our user properties. Since this design doesn’t have any labels for the text boxes, I’ve put what would be label text as the fields’ placeholder (using the placeholder attribute). These won’t display in older browsers, but that’s not relevant to our main goal here.
Now, what happens when the user clicks the “Create Account” button This form will POST to the /usersroute, resulting in the execution of the create method in the users controller. Back to that controller, then:- def create
- @user = User.new(params[:user])
- if @user.save
- redirect_to @user, notice: "Thank you for signing up for Ribbit!"
- else
- render 'new'
- end
- end
复制代码 |
|