وبلاگ رسانگار
با ما حرفه ای باشید

سرور مجازی NVMe

Ruby on Rails ( روبی آن ریلز )‌ یا RoR چیست؟

روبی آن ریل چیست و چطور استفاده می شود

0 683
زمان لازم برای مطالعه: 9 دقیقه

روبی آن ریلز چیست ؟

النا سوکولیک ، توسعه دهنده روبی آن ریلز در شرکتی روبی گاراژ می‎گوید: روبی آن رلیز یا روبی یک فرم ورک توسعه وب است که به توسعه دهندگان روبی متدهای سریع برای نوشتن کد را بدون اتلاف وقت میدهد ، روبی یکی از فریم ورک های برنامه نویسی در دنیای برنامه نویسی اپلیکیشن و توسعه وب است ، این چهارچوب های برنامه نویسی مجموعه ای از کتاابخانه های خود هستند که به توسعه دهنده وب و اپلیکیشن راه کارهای آماده استفاده برای کارهایی که پیاده سازی آنها بصورت عادی زمان بر است می‎دهد ، چیزهایی مثل ساخت من ها و جداول ، فرم ها در یک وب سایت

به عبارت دیگر بجای اینکه هر خط کد را خودتان را از پایه خودتان بنویسید توسعه دهندگان وب به فریم ورک رچوع میکنند و کد مروبط به تابع  عمومی که میتوانند در وب سایت و یا وب اپلیکشین خود قرار بدهند پیدا می کنند ، فریم ورک های تحت وب معمولا مختص به یک زبان برنامه نویسی هستند ( مثلا انگولار که فرم ورک جاوا اسکپریت است ، به این معنی است که تمام کتابخانه های کدی که دارد به زبان جاوااسکریپت نوشته شده است ) و فرم ورک ریلز نیز هم همینطور است ، ریلز به سادگی یک فرم ورک نوشته شده بر اساس روبی است

While all frameworks by their nature help to make the development of complex websites more manageable, Jasmit Kaur, Founder and CEO at talent analytics platform Culturebie, says that Rails is particularly notable for its easy maintenance and the fact that it lends itself to collaboration. Kaur says this is a result of the two key tenets Rails is founded on: DRY (Do Not Repeat Yourself) and Convention Over Configuration. Kaur points to these two descriptions from the Rails website:

  • Don’t Repeat Yourself: DRY is a principle of software development which states that “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” By not writing the same information over and over again, our code is more maintainable, more extensible, and less buggy.”
  • Convention Over Configuration: Rails has opinions about the best way to do many things in a web application, and defaults to this set of conventions, rather than require that you specify minutiae through endless configuration files.”

In other words, not only does the Rails web framework cut down on the time sink of re-coding repetitive tasks, but—by using Rails code—Rails developers keep their overall work cleaner, less prone to bugs (bad, ineffective code), and easier to troubleshoot when problems do occur. At the same time, Rails subscribes to an overall method of best practices for Rails developers that removes the need to leave behind instructions and rationale for your coding decisions (through configuration files) in the code you write—instead, Rails developers work from the shared common ground of Rails conventions. “In the past I’ve built web applications that became unwieldy pretty fast, even when they were not big projects,” Kaur says. “Rails’ two tenets help prevent that, along with a terrific Rails community of users and great open-source libraries (Rails is open-source, meaning its source code—the code that makes it work—is open to the public and the framework itself is free to use).”

Finally, Rosie Thomas, Ruby Engineer at financial data software company MX, adds that—as a web framework—Rails is most commonly used to build full web applications (web apps like GitHub, Basecamp, and Kickstarter were all built using Rails) and APIs (systems of tools and resources that are then used by developers to create software applications). Because of this, Thomas says, tech jobs that focus on providing browser-based applications or APIs are likely to use Rails and hire developers with Rails experience. As of this writing—Glassdoor lists nearly 6,000 open jobs for Ruby on Rails Developers.

روبی در این مقاله به مفاهیم پایه‌ای توسعه وب می‌پردازیم و توضیح می‌دهیم که Ruby on Rails چیست و چرا Ruby on Rails یکی از فریمورک‌های محبوب برای توسعه وب است. اصطلاحات فنی توضیح داده ‌شده‌ و با یک زبان ساده و قابل‌فهم تشریح می‌شوند. Rails گاهی با نام ROR هم شناخته می‌شود. ROR فریمورک متن‌باز برای توسعه برنامه‌های تحت وب است که از زبان روبی که یک زبان شی‌گرا مشابه پایتون است، استفاده می‌کند.

ruby on rails در واقع یک فریم‌ورک وب‌اپلیکیشن است که شامل همه موارد مورد نیاز برای ایجاد برنامه های کاربردی تحت وب مبتنی بر پایگاه داده بر اساس Model-View-Controller است.

تفاوت اصلی Ruby On Rails با دیگر فریمورک‌ها، سرعت توسعه و سهولت استفاده از آن برای توسعه‌دهندگان است.  هر تغییری که روی کد برنامه اعمال می‌شود، به‌صورت آنی نتیجه اجرای آن را می‌توانید مشاهده کنید، همچنین مراحل وقت‌گیر که هنگام کار با سایر فریمورک‌ها وجود دارد را در این فریم‌ورک نخواهید داشت.

طبق گفته David Geary  یک متخصص جاوا، فریمورک‌های مبتنی بر روبی ۵ تا ۱۰ برابر سریع‌تر از فریمورک‌های مبتنی بر جاوا هستند.

Rails از چندین کامپوننت از جمله خود روبی تشکیل شده  است که عبارت‌اند از:

  • Active Record:  یک لایه نگاشت رابطه‌ای به شی‌گرا (object-relational mapping)
  • Action pack: کنترل کننده و view functions
  • Action mailer: اداره کننده ایمیل
  • Action Web Service ها و Prototype: ایجکس و قابلیت drag & drop را پیاده‌سازی می‌کند.
پیشنهاد می‌کنیم بخوانید:  NodeJS چیست ؟ آشنایی اولیه با NodeJS

Rails در اکثر وب سرورهایی که از CGI  پشتیبانی می‌کنند می‌تواند اجرا شود.  این فریمورک از پایگاه داده‌های MySQL، PostgreSQL، SQLite،DB٢ و اورکل پشتیبانی می‌کند.

Rails از معماری MVC یا (Model-View-Controller) استفاده می‌کند. همچنین تمام لایه‌هایی که توسط Rails ارائه می‌شوند در مقایسه با دیگر فریمورک‌ها، پشتیبانی کاملی از MVC به عمل می‌آورد.

فریمورک Ruby on Rails یک پروژه متن‌باز است که توسط David Heinemeier Hanse ساخته شده و می‌توانید ورژن‌های مختلف آن را از سایت rubyonrails.org دانلود کنید.

Ruby

Ruby یک زبان برنامه‌نویسی است که در ۲۰ سال قبل توسط Yakihire Matz Matsumoto ایجاد شد.  از نظر میزان محبوبیت زبان‌های برنامه‌نویسی،  روبی جز ده زبان برتر محاسبه می‌شود، اگرچه از نظر محبوبیت در جایگاه دهم قرار دارد اما این محبوبیت را تا حد زیادی مدیون Rails است. زبان روبی مانند جاوا یا C یک زبان برنامه‌نویسی چند منظوره است، با این وجود بیشتر به‌عنوان یک زبان برنامه‌نویسی برای توسعه وب شناخته می‌شود.

Rails

Rails کتابخانه نرم‌افزاری است که قابلیت‌های زبان برنامه‌نویسی روبی را گسترش می‌دهد. خالق این کتابخانه David Heinemeier Hanse است. او نام آن را Ruby on Rails گذاشت. اما اغلب آن را تنها به‌صورت Rails می‌شناسند.

یکی از مزایای Rails نسبت به فریم‌ورک‌های دیگر این است که با آن می‌توان با سرعت بیشتر و حدود ده برابر بیشتر از سایر فریم‌ورک‌ها برنامه‌نویسی کرد. علت این سرعت بالا، استفاده از زبان Ruby و پشتیبانی از دو اصل مهمی CoC و DRY است.

Rails کتابخانه نرم‌افزاری است که به زبان برنامه‌نویسی روبی اضافه شده و از نظر فنی، یک package library برای (RubyGem) است که با استفاده از ابزار خط فرمان سیستم‌عامل نصب می‌شود. Rails یک فریمورک برای ساخت وب‌سایت است. به این ترتیب Rails یک سری از قراردادها را برای افزایش اشتراک‌پذیری و قابلیت نگهداری برنامه ایجاد می‌کند. این قراردادها به‌عنوان Api‌ های Rails یا Rails API شناخته  می‌شوند.(API= رابط برنامه‌نویسی کاربردی یا دستوراتی که کد برنامه را کنترل می‌کند.)

Rails API شامل داکیومنت‌های آنلاین است و در قالب کتاب‌ها، مقالات و پست‌های وبلاگ توضیح داده‌ شده‌اند. یادگیری Rails به معنی یادگیری چگونگی استفاده از قراردادهای Rails و APIهای آن است. Rails زبان برنامه‌نویسی روبی را با Html ،CSS و جاوااسکریپت به‌منظور ساخت برنامه‌های تحت وب که روی یک وب سرور اجرا می‌شود، ترکیب می‌کند.

از آن‌جایی که Rails روی یک وب سرور اجرا می‌شود، به‌عنوان یک پلتفرم توسعه وب سمت سرور یا backend شناخته می‌شود (همچنین برنامه‌هایی که در مرورگر اجرا می‌شوند، اصطلاحاً front end می‌گویند)

Rails از یک دید بالاتر، چیزی بیش از یک کتابخانه نرم‌افزاری یا یک API است. Rails پروژه مرکزی یک جامعه گسترده‌ای است که کتابخانه‌های نرم‌افزاری تولید می‌کنند و از این طریق کار ساختن وب‌سایت‌های پیچیده را آسان می‌کنند.

اعضای جامعه Rails بسیاری از ارزش‌های اصلی را به اشتراک می‌گذارند، اغلب از ابزارهای یکسانی استفاده می‌کنند و با یک شبکه غیررسمی که برای فعالیت‌های داوطلبانه ساخته شده، از یکدیگر پشتیبانی می‌کنند. این جامعه غیررسمی از یک شبکه اقتصادی که شامل مشاغل، شرکت‌های مشاوره‌ای، کنفرانس‌ها و کسب‌وکارها و سرمایه‌گذارانی که هزینه‌های یک استارت‌آپ را تأمین می‌کنند، تشکیل می‌شوند.

Rails در میان شرکت‌های نوپا بسیار محبوب است. به این دلیل ک شامل مجموعه‌ای از نرم‌افزارهای متن‌باز (RubyGem یا Gem) است که امکان ساخت سریع سایت‌های پیچیده را ارائه می‌دهد

 

آیا Rails برای برنامه‎نویسان تازه‎کار مناسب است  ؟

While HTML and CSS (markup languages used to define the parts of webpages and to adjust colors, fonts, etc.) are often pointed to as gateways for becoming a web developer, where does that leave web frameworks like Rails? Is Rails something to tackle only after you’re deep in the throes of tech skills, or is it something that’s in reach for a beginning web developer, too?

According to Laura Bârlădeanu, Tech Lead at mind mapping software company MindMeister, Rails is actually very beginner friendly. In fact, Bârlădeanu says, Rails is SO beginner friendly that she and other program organizers are able to teach women and girls who’ve never programmed before how to use Rails in only one day during Rails Girls workshops. Rails Girls is a global, non-profit volunteer community dedicated to helping women understand technology, and the entire enterprise was founded on the back of Rails as an instructional tool. “I’ve coached at several of these events, and I can safely say that Rails is a very suitable framework to learn as an entry into programming,” Bârlădeanu says.

However, to talk about Rails and its relevance for beginners, it’s important to take a step back and understand that it’s not just the Rails framework that’s beginner friendly, but the Ruby language it’s built on as well. “Rails IS Ruby,” Bârlădeanu says, “or it at least exists on top of Ruby.” According to Bârlădeanu, this means that understanding Rails will involve learning at least some parts of the Ruby programming language—though nothing beyond basic concepts and syntax. “Ruby is a scripting language that has more applications than using it through Rails,” Bârlădeanu says. “For instance, Ruby developers can use it to write a script that moves all your music files that have the name of your favorite band into a folder with that band’s name.” Bârlădeanu says to think of the Ruby language like flour—you can use it to make bread (or Rails), but also pizza, shortbread, etc.

Thomas reiterates that the Ruby language itself—and not just the Rails web framework—is a solid choice as a beginning coding language. “It’s what I started with!” says Thomas. “It’s easy to read and does a lot of the work for you. Other languages, like C, require a lot more code to do something you can accomplish in a few lines with Ruby.” While Thomas says this isn’t without some drawbacks—more complicated programming languages ultimately offer more options and control—it works out well for someone just getting started with web development. Thomas also says that Ruby is more than capable of carrying you through to an intermediate level of programming. “I’ve been using Ruby and Rails for three years now, and I don’t see myself stopping any time soon,” Thomas says. “Rails is like an extension of Ruby—once you’ve learned Ruby basics you can start to learn Ruby on Rails.”

پیشنهاد می‌کنیم بخوانید:  NodeJS چیست ؟ آشنایی اولیه با NodeJS

چه چیزی روبی را از دیگر زبان های برنامه نویسی و فریم‎ورک ها متفاوت کردهاست ؟

So we know that Rails is a framework that lets Rails developers harness the Ruby language for developing websites, and both Ruby and Rails are good skills to learn for tech beginners, but what exactly sets Ruby and Rails apart from other programming languages and web frameworks? Why would someone use Rails to build a web app instead of HTML, or CSS, or JavaScript?

Sokolyk says one of Ruby’s key characteristics is that it’s an object-oriented programming language. Unlike some languages that function by giving a computer a list of tasks to execute, an object-oriented programming language lets a developer create virtual objects in their code. Each object can have its own specific attributes and abilities and can interact with other objects to perform actions. Groups of objects can then be given instructions based on those attributes and how they relate to one another. If you think of objects like virtual building blocks, a group of A blocks can be used to build a tower, while a group of B blocks can be instructed to create steps leading to the top of the tower. An object-oriented language makes development less complex by giving programmers structures to work with that resemble building in the real world. Objects can also be easily reused in future programs.

To give an example of what programming with Ruby looks like, compare writing a simple function in Ruby with writing the same function with PHP (another scripting language that can be used for similar functions as Ruby).

To print the worlds Hello World on a web browser screen in PHP you would need to write:

echo “Hello World”;

Notice the non-intuitive use of a semicolon and the command “echo.”

On the other hand, to do the same thing with Ruby you would simply write is

puts “Hello World”

Ruby lacks the extraneous semicolon, and uses the more spoken-language-like “puts” command. Extrapolate this small example into hours a day writing code with increasingly longer and complex functions, and you can see how the Ruby interface can save time and boost efficiency.

Where Rails comes into play is that if you were to simply write “puts “Hello World”” in an HTML document, if would show up exactly as written in a web browser. Rails provides the framework for entering these Ruby commands into the code of a website or web application.

Finally, where Ruby and Rails really differentiate themselves from other web development languages (HTML, CSS, JavaScript, etc.) is that HTML, CSS, and JavaScript all define and control the “front end” aspects of websites and web apps—the things a user sees and interacts with through their web browser. Meanwhile, Ruby on Rails works on the back end of websites and apps to request and fetch data from databases and to display data that contains HTML, CSS, and JavaScript content.

What Are Some Ways to Learn Ruby on Rails and How Long Should You Expect it to Take?

When it comes to learning Ruby on Rails, you can start picking up skills from the usual suspects—you can take a free Ruby on Rails tutorial from sites like Udemy and Code Academy, enroll in a paid online class with instructor support, or learn tips from forums on programming sites like Stack Overflow. Because of Rails’ strong community support, there are also dedicated Rails organizations (like Rails Girls mentioned above, and RailsBridge) that offer Rails classes, meetups, and workshops. Sokolyk says that she learned Rails through courses organized by RubyGarage, the company she now works for. This led to an internship after she graduated, and eventually a full-time position as part of their web development team. Meanwhile, Thomas learned Ruby and Rails by attending a three-month long bootcamp program with two instructors and about 20 other students. Thomas worked as a TA at the bootcamp after she completed the program, and says that teaching helped solidify what she learned.

As far as how long you should expect the Rails learning process to take? When it comes to nailing down the basics you can expect a relatively short learning curve. Bârlădeanu wrote her first lines of code in Rails on her first day of working with the framework and was able to build a Rails application after one month, while Kaur says it took her about five days to familiarize herself with Rails to the point where she could make a simple web app. However, once you have the basics handled, Thomas says working with Ruby and Rails will be a constant learning process. “I still learn things I didn’t know, and that’s half the fun,” says Thomas.

The takeaway? Ruby on Rails is a powerful web development tool that adds a back end dimension to front end skills like HTML, CSS, and JavaScript. While Rails is a crucial skill to add if you already have tech skills, it’s also user-friendly enough to be a totally manageable entry point into programming and web development.

 

4.5/5 (17 رای)
دیدگاه شما در خصوص مطلب چیست ؟

آدرس ایمیل شما منتشر نخواهد شد.

لطفا دیدگاه خود را با احترام به دیدگاه های دیگران و با توجه به محتوای مطلب درج کنید