concept true in category rails

appears as: true
Rails 4 in Action: Revised Edition of Rails 3 in Action

This is an excerpt from Manning's book Rails 4 in Action: Revised Edition of Rails 3 in Action.

Inside respond_to is an if statement that calls @purchase.save. This method validates the record; and if it’s valid, the method saves the record to the database and returns true.

If the return value is true, the action responds by redirecting to the new @purchase object using the redirect_to method, which takes either a path or an object that it turns into a path (as seen in listing 1.6). The redirect_to method inspects the @purchase object and determines that the path required is purchase_path because it’s an instance of the Purchase model. This path takes you to the show action for this controller. The :notice option passed to redirect_to sets up a flash message, which is a message that can be displayed on the next request. This is the green text at the top of figure 1.4.

When you call any?, it calls the ActiveRecord::Base association method, which checks whether there are any attachments on a ticket and returns true if there are. Although attachments isn’t yet defined, you can probably guess what you’re about to do.

Capybara provides an easy way to trigger WebDriver testing. You tag a scenario (or feature) with the js: true option, and it launches a new web browser window and tests your code by using the same steps as standard Capybara testing, but in a browser. Isn’t that neat?

Rails 3 in Action

This is an excerpt from Manning's book Rails 3 in Action.

Inside the respond_to is an if statement that calls @purchase.save. This method validates the record, and if it’s valid, the method saves the record to the database and returns true.

If the return value is true, the action responds by redirecting to the new @purchase object using the redirect_to method, which takes either a path or an object that it turns into a path (as seen in this example). The redirect_to method interprets what the @purchase object is and determines that the path required is purchase_path because it’s an object of the Purchase model. This path takes you to the show action for this controller. The :notice option passed to the redirect_to sets up a flash message. A flash message is a message that can be displayed on the next request.

If you pass the admin attribute in your table, it’ll be a string. You check whether the string is equal to true, and if it is, you use update_attribute to set the admin field manually to true or false, depending on whether or not attributes["admin"] is true.

Although it’s fine and dandy to ensure that admin users can get to special places in your application, you haven’t yet added the functionality for triggering whether or not a user is an admin from within the application itself. To do so, you create a new namespaced section of your site called admin. The purpose of namespacing in this case is to separate a controller from the main area of the site so you can ensure that users accessing this particular controller (and any future controllers you create in this namespace) have the admin field set to true.