Be careful when writing Rails Projects

Source: Internet
Author: User

Be careful when writing Rails Projects

1. If the form contains data to be sent back to the server, you can use the hidden property control:

Form_for (xxx) do | f |

F. hidden_field: xxx, value: xxx

End

2. If you need some information in the global page framework, but the information belongs to some specific pages, you can use the following method:

<% Content_for: QuestionsCount do %>
<% = @ Question. length if @ question %>
<% = 0 unless @ question %>
<% End %>

Add the following code to pipeline. erb:

<Title> Exams (questions in the question bank <% = yield: QuestionsCount %>) </title>

3. in some redirection or render operations, we may not need to display the page to be redirected in the default page framework. We hope to use a special page framework; in this case, you can manually specify a page framework:

Respond_to do | format |
Format.html {render layout: "my_layout "}
End

4. in some cases, we hope that the email field in the mode can be null or be in a certain format. If validates_format_of is used for verification, we will find that verification fails if its value is null, in addition to the Verification Method with higher degrees of freedom, there is also a simple way to set the allow_blank parameter of validates_format_of to true:

Validates_format_of: email ,\
With:/\ A [^ @] [\ w. -] + @ [\ w. -] + [.] [a-z] {2, 4} \ z/I, allow_blank: true, message: "Incorrect email format"

Install Apache server in Ubuntu and use the Passenger plug-in to deploy Rails Applications

Build a Ruby On Rails platform using CentOS

Build Ruby On Rails in Ubuntu

Web development agile way application Rails agile Web development (original book version 4th). (US) Sam Ruby). [PDF] + source code

For details about Rails, click here
Rails: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.