In this step-by-step overview, learn how to use GIMP. We start with how to download and install GIMP. We then explore the interface, including the toolbox, tool options, color selection, docks / tabs, and the menu system. Next, we look at all the options to customize the experience, from resizing docks, to turning on or off single window mode, to changing icon colors, and adjusting the theme from dark to light.
We continue by creating a new file and saving it. We then navigate through the canvas using various short cut keys. We then load some sample files, learn about layers, arrange the layers, and apply different opacities. We add text, use the selection tools, align objects, use brushes, filters, and colors. By the end of this video, you'll have foundational knowledge of how to use GIMP to start editing images. And best of all, you'll have your first image created in GIMP… a poster for the Kevin Cookie Company!
0:53 Download & install GIMP
1:26 Main interface
4:41 Top Menu
6:33 Customize interface
8:14 Create new file
9:38 Save as xcf
10:21 View shortcuts
10:58 Import sample image files
13:09 Scale / resize image
14:14 Bucket fill tool
16:32 Selection tools
20:22 Text tools
22:03 Add text drop shadow
22:34 Group layers
23:21 Remove image background
25:52 Flip image
26:20 Alignment tool
26:48 Adjust colors - curves
29:51 Crop tool
31:27 Move text
31:55 Paintbrush tool
34:33 Gaussian Blur
35:13 Export as .png, .jpeg, or .gif
36:07 Wrap up
- GIMP home page: https://www.gimp.org/
- Sample image files to follow along: https://1drv.ms/u/s!AmxrofZZlZ-whM8bZTtkFXc4S9RtTQ?e=Fgpn2N
🔔 Subscribe to my YouTube channel
The era of mobile app development has completely changed the scenario for businesses in regions like Abu Dhabi. Restaurants and food delivery businesses are experiencing huge benefits via smart business applications. The invention and development of the food ordering app have helped all-scale businesses reach new customers and boost sales and profit.
As a result, many business owners are searching for the best restaurant mobile app development company in Abu Dhabi. If you are also searching for the same, this article is helpful for you. It will let you know the step-by-step process to hire the right team of restaurant mobile app developers.
Searching for the top mobile app development company in Abu Dhabi? Don't know the best way to search for professionals? Don't panic! Here is the step-by-step process to hire the best professionals.
#Step 1 – Know the Company's Culture
Knowing the organization's culture is very crucial before finalizing a food ordering app development company in Abu Dhabi. An organization's personality is shaped by its common beliefs, goals, practices, or company culture. So, digging into the company culture reveals the core beliefs of the organization, its objectives, and its development team.
Now, you might be wondering, how will you identify the company's culture? Well, you can take reference from the following sources –
#Step 2 - Refer to Clients' Reviews
Another best way to choose the On-demand app development firm for your restaurant business is to refer to the clients' reviews. Reviews are frequently available on the organization's website with a tag of "Reviews" or "Testimonials." It's important to read the reviews as they will help you determine how happy customers are with the company's app development process.
You can also assess a company's abilities through reviews and customer testimonials. They can let you know if the mobile app developers create a valuable app or not.
#Step 3 – Analyze the App Development Process
Regardless of the company's size or scope, adhering to the restaurant delivery app development process will ensure the success of your business application. Knowing the processes an app developer follows in designing and producing a top-notch app will help you know the working process. Organizations follow different app development approaches, so getting well-versed in the process is essential before finalizing any mobile app development company.
#Step 4 – Consider Previous Experience
Besides considering other factors, considering the previous experience of the developers is a must. You can obtain a broad sense of the developer's capacity to assist you in creating a unique mobile application for a restaurant business.
You can also find out if the developers' have contributed to the creation of other successful applications or not. It will help you know the working capacity of a particular developer or organization. Prior experience is essential to evaluating their work. For instance, whether they haven't previously produced an app similar to yours or not.
#Step 5 – Check for Their Technical Support
As you expect a working and successful restaurant mobile app for your business, checking on this factor is a must. A well-established organization is nothing without a good technical support team. So, ensure whatever restaurant mobile app development company you choose they must be well-equipped with a team of dedicated developers, designers, and testers.
Strong tech support from your mobile app developers will help you identify new bugs and fix them bugs on time. All this will ensure the application's success.
#Step 6 – Analyze Design Standards
Besides focusing on an organization's development, testing, and technical support, you should check the design standards. An appealing design is crucial in attracting new users and keeping the existing ones stick to your services. So, spend some time analyzing the design standards of an organization. Now, you might be wondering, how will you do it? Simple! By looking at the organization's portfolio.
Whether hiring an iPhone app development company or any other, these steps apply to all. So, don't miss these steps.
#Step 7 – Know Their Location
Finally, the last yet very crucial factor that will not only help you finalize the right person for your restaurant mobile app development but will also decide the mobile app development cost. So, you have to choose the location of the developers wisely, as it is a crucial factor in defining the cost.
Restaurant mobile applications have taken the food industry to heights none have ever considered. As a result, the demand for restaurant mobile app development companies has risen greatly, which is why businesses find it difficult to finalize the right person. But, we hope that after referring to this article, it will now be easier to hire dedicated developers under the desired budget. So, begin the hiring process now and get a well-craft food ordering app in hand.
This Matplotlib cheat sheet introduces you to the basics that you need to plot your data with Python and includes code samples.
Data visualization and storytelling with your data are essential skills that every data scientist needs to communicate insights gained from analyses effectively to any audience out there.
For most beginners, the first package that they use to get in touch with data visualization and storytelling is, naturally, Matplotlib: it is a Python 2D plotting library that enables users to make publication-quality figures. But, what might be even more convincing is the fact that other packages, such as Pandas, intend to build more plotting integration with Matplotlib as time goes on.
However, what might slow down beginners is the fact that this package is pretty extensive. There is so much that you can do with it and it might be hard to still keep a structure when you're learning how to work with Matplotlib.
DataCamp has created a Matplotlib cheat sheet for those who might already know how to use the package to their advantage to make beautiful plots in Python, but that still want to keep a one-page reference handy. Of course, for those who don't know how to work with Matplotlib, this might be the extra push be convinced and to finally get started with data visualization in Python.
You'll see that this cheat sheet presents you with the six basic steps that you can go through to make beautiful plots.
Check out the infographic by clicking on the button below:
With this handy reference, you'll familiarize yourself in no time with the basics of Matplotlib: you'll learn how you can prepare your data, create a new plot, use some basic plotting routines to your advantage, add customizations to your plots, and save, show and close the plots that you make.
Matplotlib is a Python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms.
>>> import numpy as np >>> x = np.linspace(0, 10, 100) >>> y = np.cos(x) >>> z = np.sin(x)
>>> data = 2 * np.random.random((10, 10)) >>> data2 = 3 * np.random.random((10, 10)) >>> Y, X = np.mgrid[-3:3:100j, -3:3:100j] >>> U = 1 X** 2 + Y >>> V = 1 + X Y**2 >>> from matplotlib.cbook import get_sample_data >>> img = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure() >>> fig2 = plt.figure(figsize=plt.figaspect(2.0))
>>> fig.add_axes() >>> ax1 = fig.add_subplot(221) #row-col-num >>> ax3 = fig.add_subplot(212) >>> fig3, axes = plt.subplots(nrows=2,ncols=2) >>> fig4, axes2 = plt.subplots(ncols=3)
>>> plt.savefig('foo.png') #Save figures >>> plt.savefig('foo.png', transparent=True) #Save transparent figures
>>> fig, ax = plt.subplots() >>> lines = ax.plot(x,y) #Draw points with lines or markers connecting them >>> ax.scatter(x,y) #Draw unconnected points, scaled or colored >>> axes[0,0].bar([1,2,3],[3,4,5]) #Plot vertical rectangles (constant width) >>> axes[1,0].barh([0.5,1,2.5],[0,1,2]) #Plot horiontal rectangles (constant height) >>> axes[1,1].axhline(0.45) #Draw a horizontal line across axes >>> axes[0,1].axvline(0.65) #Draw a vertical line across axes >>> ax.fill(x,y,color='blue') #Draw filled polygons >>> ax.fill_between(x,y,color='yellow') #Fill between y values and 0
>>> fig, ax = plt.subplots() >>> im = ax.imshow(img, #Colormapped or RGB arrays cmap= 'gist_earth', interpolation= 'nearest', vmin=-2, vmax=2) >>> axes2.pcolor(data2) #Pseudocolor plot of 2D array >>> axes2.pcolormesh(data) #Pseudocolor plot of 2D array >>> CS = plt.contour(Y,X,U) #Plot contours >>> axes2.contourf(data1) #Plot filled contours >>> axes2= ax.clabel(CS) #Label a contour plot
>>> axes[0,1].arrow(0,0,0.5,0.5) #Add an arrow to the axes >>> axes[1,1].quiver(y,z) #Plot a 2D field of arrows >>> axes[0,1].streamplot(X,Y,U,V) #Plot a 2D field of arrows
>>> ax1.hist(y) #Plot a histogram >>> ax3.boxplot(y) #Make a box and whisker plot >>> ax3.violinplot(z) #Make a violin plot
The basic steps to creating plots with matplotlib are:
1 Prepare Data
2 Create Plot
4 Customized Plot
5 Save Plot
6 Show Plot
>>> import matplotlib.pyplot as plt >>> x = [1,2,3,4] #Step 1 >>> y = [10,20,25,30] >>> fig = plt.figure() #Step 2 >>> ax = fig.add_subplot(111) #Step 3 >>> ax.plot(x, y, color= 'lightblue', linewidth=3) #Step 3, 4 >>> ax.scatter([2,4,6], [5,15,25], color= 'darkgreen', marker= '^' ) >>> ax.set_xlim(1, 6.5) >>> plt.savefig('foo.png' ) #Step 5 >>> plt.show() #Step 6
>>> plt.cla() #Clear an axis >>> plt.clf(). #Clear the entire figure >>> plt.close(). #Close a window
>>> plt.plot(x, x, x, x**2, x, x** 3) >>> ax.plot(x, y, alpha = 0.4) >>> ax.plot(x, y, c= 'k') >>> fig.colorbar(im, orientation= 'horizontal') >>> im = ax.imshow(img, cmap= 'seismic' )
>>> fig, ax = plt.subplots() >>> ax.scatter(x,y,marker= ".") >>> ax.plot(x,y,marker= "o")
>>> plt.plot(x,y,linewidth=4.0) >>> plt.plot(x,y,ls= 'solid') >>> plt.plot(x,y,ls= '--') >>> plt.plot(x,y,'--' ,x**2,y**2,'-.' ) >>> plt.setp(lines,color= 'r',linewidth=4.0)
>>> ax.text(1, -2.1, 'Example Graph', style= 'italic' ) >>> ax.annotate("Sine", xy=(8, 0), xycoords= 'data', xytext=(10.5, 0), textcoords= 'data', arrowprops=dict(arrowstyle= "->", connectionstyle="arc3"),)
>>> plt.title(r '$sigma_i=15$', fontsize=20)
Limits & Autoscaling
>>> ax.margins(x=0.0,y=0.1) #Add padding to a plot >>> ax.axis('equal') #Set the aspect ratio of the plot to 1 >>> ax.set(xlim=[0,10.5],ylim=[-1.5,1.5]) #Set limits for x-and y-axis >>> ax.set_xlim(0,10.5) #Set limits for x-axis
>>> ax.set(title= 'An Example Axes', #Set a title and x-and y-axis labels ylabel= 'Y-Axis', xlabel= 'X-Axis') >>> ax.legend(loc= 'best') #No overlapping plot elements
>>> ax.xaxis.set(ticks=range(1,5), #Manually set x-ticks ticklabels=[3,100, 12,"foo" ]) >>> ax.tick_params(axis= 'y', #Make y-ticks longer and go in and out direction= 'inout', length=10)
>>> fig3.subplots_adjust(wspace=0.5, #Adjust the spacing between subplots hspace=0.3, left=0.125, right=0.9, top=0.9, bottom=0.1) >>> fig.tight_layout() #Fit subplot(s) in to the figure area
>>> ax1.spines[ 'top'].set_visible(False) #Make the top axis line for a plot invisible >>> ax1.spines['bottom' ].set_position(( 'outward',10)) #Move the bottom axis line outward
Original article source at https://www.datacamp.com
#matplotlib #cheatsheet #python
A handy cheat sheet for interactive plotting and statistical charts with Bokeh.
Bokeh distinguishes itself from other Python visualization libraries such as Matplotlib or Seaborn in the fact that it is an interactive visualization library that is ideal for anyone who would like to quickly and easily create interactive plots, dashboards, and data applications.
Bokeh is also known for enabling high-performance visual presentation of large data sets in modern web browsers.
For data scientists, Bokeh is the ideal tool to build statistical charts quickly and easily; But there are also other advantages, such as the various output options and the fact that you can embed your visualizations in applications. And let's not forget that the wide variety of visualization customization options makes this Python library an indispensable tool for your data science toolbox.
Now, DataCamp has created a Bokeh cheat sheet for those who have already taken the course and that still want a handy one-page reference or for those who need an extra push to get started.
In short, you'll see that this cheat sheet not only presents you with the five steps that you can go through to make beautiful plots but will also introduce you to the basics of statistical charts.
In no time, this Bokeh cheat sheet will make you familiar with how you can prepare your data, create a new plot, add renderers for your data with custom visualizations, output your plot and save or show it. And the creation of basic statistical charts will hold no secrets for you any longer.
Boost your Python data visualizations now with the help of Bokeh! :)
The Python interactive visualization library Bokeh enables high-performance visual presentation of large datasets in modern web browsers.
Bokeh's mid-level general-purpose bokeh. plotting interface is centered around two main components: data and glyphs.
The basic steps to creating plots with the bokeh. plotting interface are:
>>> from bokeh.plotting import figure >>> from bokeh.io import output_file, show >>> x = [1, 2, 3, 4, 5] #Step 1 >>> y = [6, 7, 2, 4, 5] >>> p = figure(title="simple line example", #Step 2 x_axis_label='x', y_axis_label='y') >>> p.line(x, y, legend="Temp.", line_width=2) #Step 3 >>> output_file("lines.html") #Step 4 >>> show(p) #Step 5
Under the hood, your data is converted to Column Data Sources. You can also do this manually:
>>> import numpy as np >>> import pandas as pd >>> df = pd.OataFrame(np.array([[33.9,4,65, 'US'], [32.4, 4, 66, 'Asia'], [21.4, 4, 109, 'Europe']]), columns= ['mpg', 'cyl', 'hp', 'origin'], index=['Toyota', 'Fiat', 'Volvo']) >>> from bokeh.models import ColumnOataSource >>> cds_df = ColumnOataSource(df)
>>> from bokeh.plotting import figure >>>p1= figure(plot_width=300, tools='pan,box_zoom') >>> p2 = figure(plot_width=300, plot_height=300, x_range=(0, 8), y_range=(0, 8)) >>> p3 = figure()
>>> p1.circle(np.array([1,2,3]), np.array([3,2,1]), fill_color='white') >>> p2.square(np.array([1.5,3.5,5.5]), [1,4,3], color='blue', size=1)
>>> pl.line([1,2,3,4], [3,4,5,6], line_width=2) >>> p2.multi_line(pd.DataFrame([[1,2,3],[5,6,7]]), pd.DataFrame([[3,4,5],[3,2,1]]), color="blue")
Selection and Non-Selection Glyphs
>>> p = figure(tools='box_select') >>> p. circle ('mpg', 'cyl', source=cds_df, selection_color='red', nonselection_alpha=0.1)
>>> from bokeh.models import HoverTool >>>hover= HoverTool(tooltips=None, mode='vline') >>> p3.add_tools(hover)
>>> from bokeh.models import CategoricalColorMapper >>> color_mapper = CategoricalColorMapper( factors= ['US', 'Asia', 'Europe'], palette= ['blue', 'red', 'green']) >>> p3. circle ('mpg', 'cyl', source=cds_df, color=dict(field='origin', transform=color_mapper), legend='Origin')
>>> from bokeh.io import output_notebook, show >>> output_notebook()
>>> from bokeh.embed import file_html >>> from bokeh.resources import CON >>> html = file_html(p, CON, "my_plot") >>> from bokeh.io import output_file, show >>> output_file('my_bar_chart.html', mode='cdn')
>>> from bokeh.embed import components >>> script, div= components(p)
>>> from bokeh.io import export_png >>> export_png(p, filename="plot.png")
>>> from bokeh.io import export_svgs >>> p. output_backend = "svg" >>> export_svgs(p,filename="plot.svg")
Inside Plot Area
>>> p.legend.location = 'bottom left'
Outside Plot Area
>>> from bokeh.models import Legend >>> r1 = p2.asterisk(np.array([1,2,3]), np.array([3,2,1]) >>> r2 = p2.line([1,2,3,4], [3,4,5,6]) >>> legend = Legend(items=[("One" ,[p1, r1]),("Two",[r2])], location=(0, -30)) >>> p.add_layout(legend, 'right')
>>> p.legend. border_line_color = "navy" >>> p.legend.background_fill_color = "white"
>>> p.legend.orientation = "horizontal" >>> p.legend.orientation = "vertical"
>>> from bokeh.layouts import row >>>layout= row(p1,p2,p3)
>>> from bokeh.layouts import columns >>>layout= column(p1,p2,p3)
Nesting Rows & Columns
>>>layout= row(column(p1,p2), p3)
>>> from bokeh.layouts import gridplot >>> rowl = [p1,p2] >>> row2 = [p3] >>> layout = gridplot([[p1, p2],[p3]])
>>> from bokeh.models.widgets import Panel, Tabs >>> tab1 = Panel(child=p1, title="tab1") >>> tab2 = Panel(child=p2, title="tab2") >>> layout = Tabs(tabs=[tab1, tab2])
Linked Axes >>> p2.x_range = p1.x_range >>> p2.y_range = p1.y_range
>>> p4 = figure(plot_width = 100, tools='box_select,lasso_select') >>> p4.circle('mpg', 'cyl' , source=cds_df) >>> p5 = figure(plot_width = 200, tools='box_select,lasso_select') >>> p5.circle('mpg', 'hp', source=cds df) >>>layout= row(p4,p5)
>>> show(p1) >>> show(layout) >>> save(p1)
Original article source at https://www.datacamp.com
#python #datavisualization #bokeh #cheatsheet
Can you use WordPress for anything other than blogging? To your surprise, yes. WordPress is more than just a blogging tool, and it has helped thousands of websites and web applications to thrive. The use of WordPress powers around 40% of online projects, and today in our blog, we would visit some amazing uses of WordPress other than blogging.
What Is The Use Of WordPress?
WordPress is the most popular website platform in the world. It is the first choice of businesses that want to set a feature-rich and dynamic Content Management System. So, if you ask what WordPress is used for, the answer is – everything. It is a super-flexible, feature-rich and secure platform that offers everything to build unique websites and applications. Let’s start knowing them:
1. Multiple Websites Under A Single Installation
WordPress Multisite allows you to develop multiple sites from a single WordPress installation. You can download WordPress and start building websites you want to launch under a single server. Literally speaking, you can handle hundreds of sites from one single dashboard, which now needs applause.
It is a highly efficient platform that allows you to easily run several websites under the same login credentials. One of the best things about WordPress is the themes it has to offer. You can simply download them and plugin for various sites and save space on sites without losing their speed.
2. WordPress Social Network
WordPress can be used for high-end projects such as Social Media Network. If you don’t have the money and patience to hire a coder and invest months in building a feature-rich social media site, go for WordPress. It is one of the most amazing uses of WordPress. Its stunning CMS is unbeatable. And you can build sites as good as Facebook or Reddit etc. It can just make the process a lot easier.
To set up a social media network, you would have to download a WordPress Plugin called BuddyPress. It would allow you to connect a community page with ease and would provide all the necessary features of a community or social media. It has direct messaging, activity stream, user groups, extended profiles, and so much more. You just have to download and configure it.
If BuddyPress doesn’t meet all your needs, don’t give up on your dreams. You can try out WP Symposium or PeepSo. There are also several themes you can use to build a social network.
3. Create A Forum For Your Brand’s Community
Communities are very important for your business. They help you stay in constant connection with your users and consumers. And allow you to turn them into a loyal customer base. Meanwhile, there are many good technologies that can be used for building a community page – the good old WordPress is still the best.
It is the best community development technology. If you want to build your online community, you need to consider all the amazing features you get with WordPress. Plugins such as BB Press is an open-source, template-driven PHP/ MySQL forum software. It is very simple and doesn’t hamper the experience of the website.
Other tools such as wpFoRo and Asgaros Forum are equally good for creating a community blog. They are lightweight tools that are easy to manage and integrate with your WordPress site easily. However, there is only one tiny problem; you need to have some technical knowledge to build a WordPress Community blog page.
Since we gave you a problem in the previous section, we would also give you a perfect solution for it. You might not know to code, but you have shortcodes. Shortcodes help you execute functions without having to code. It is an easy way to build an amazing website, add new features, customize plugins easily. They are short lines of code, and rather than memorizing multiple lines; you can have zero technical knowledge and start building a feature-rich website or application.
There are also plugins like Shortcoder, Shortcodes Ultimate, and the Basics available on WordPress that can be used, and you would not even have to remember the shortcodes.
5. Build Online Stores
If you still think about why to use WordPress, use it to build an online store. You can start selling your goods online and start selling. It is an affordable technology that helps you build a feature-rich eCommerce store with WordPress.
WooCommerce is an extension of WordPress and is one of the most used eCommerce solutions. WooCommerce holds a 28% share of the global market and is one of the best ways to set up an online store. It allows you to build user-friendly and professional online stores and has thousands of free and paid extensions. Moreover as an open-source platform, and you don’t have to pay for the license.
Apart from WooCommerce, there are Easy Digital Downloads, iThemes Exchange, Shopify eCommerce plugin, and so much more available.
6. Security Features
WordPress takes security very seriously. It offers tons of external solutions that help you in safeguarding your WordPress site. While there is no way to ensure 100% security, it provides regular updates with security patches and provides several plugins to help with backups, two-factor authorization, and more.
By choosing hosting providers like WP Engine, you can improve the security of the website. It helps in threat detection, manage patching and updates, and internal security audits for the customers, and so much more.
#use of wordpress #use wordpress for business website #use wordpress for website #what is use of wordpress #why use wordpress #why use wordpress to build a website
This project is based on the need for a private message system for ging / social_stream. Instead of creating our core message system heavily dependent on our development, we are trying to implement a generic and potent messaging gem.
After looking for a good gem to use we noticed the lack of messaging gems and functionality in them. Mailboxer tries to fill this void delivering a powerful and flexible message system. It supports the use of conversations with two or more participants, sending notifications to recipients (intended to be used as system notifications “Your picture has new comments”, “John Doe has updated his document”, etc.), and emailing the messageable model (if configured to do so). It has a complete implementation of a
Mailbox object for each messageable with
The gem is constantly growing and improving its functionality. As it is used with our parallel development ging / social_stream we are finding and fixing bugs continously. If you want some functionality not supported yet or marked as TODO, you can create an issue to ask for it. It will be great feedback for us, and we will know what you may find useful in the gem.
Mailboxer was born from the great, but outdated, code from lpsergi / acts_as_messageable.
We are now working to make exhaustive documentation and some wiki pages in order to make it even easier to use the gem to its full potential. Please, give us some time if you find something missing or ask for it. You can also find us on the Gitter room for this repo. Join us there to talk.
Add to your Gemfile:
$ bundle install
Run install script:
$ rails g mailboxer:install
And don't forget to migrate your database:
$ rake db:migrate
You can also generate email views:
$ rails g mailboxer:views
If upgrading from 0.11.0 to 0.12.0, run the following generators:
$ rails generate mailboxer:namespacing_compatibility $ rails generate mailboxer:install -s
Then, migrate your database:
$ rake db:migrate
We are now adding support for sending emails when a Notification or a Message is sent to one or more recipients. You should modify the mailboxer initializer (/config/initializer/mailboxer.rb) to edit these settings:
Mailboxer.setup do |config| #Enables or disables email sending for Notifications and Messages config.uses_emails = true #Configures the default `from` address for the email sent for Messages and Notifications of Mailboxer config.default_from = "email@example.com" ... end
You can change the way in which emails are delivered by specifying a custom implementation of notification and message mailers:
Mailboxer.setup do |config| config.notification_mailer = CustomNotificationMailer config.message_mailer = CustomMessageMailer ... end
If you have subclassed the Mailboxer::Notification class, you can specify the mailers using a member method:
class NewDocumentNotification < Mailboxer::Notification def mailer_class NewDocumentNotificationMailer end end class NewCommentNotification < Mailboxer::Notification def mailer_class NewDocumentNotificationMailer end end
Otherwise, the mailer class will be determined by appending 'Mailer' to the mailable class name.
Users must have an identity defined by a
name and an
#Returning any kind of identification you want for the model def name return "You should add method :name in your Messageable model" end
#Returning the email address of the model if an email should be sent for this object (Message or Notification). #If no mail has to be sent, return nil. def mailboxer_email(object) #Check if an email should be sent for that object #if true return "define_email@on_your.model" #if false #return nil end
These names are explicit enough to avoid colliding with other methods, but as long as you need to change them you can do it by using mailboxer initializer (/config/initializer/mailboxer.rb). Just add or uncomment the following lines:
Mailboxer.setup do |config| # ... #Configures the methods needed by mailboxer config.email_method = :mailboxer_email config.name_method = :name config.notify_method = :notify # ... end
You may change whatever you want or need. For example:
config.email_method = :notification_email config.name_method = :display_name config.notify_method = :notify_mailboxer
Will use the method
notification_email(object) instead of
Using default or custom method names, if your model doesn't implement them, Mailboxer will use dummy methods so as to notify you of missing methods rather than crashing.
In your model:
class User < ActiveRecord::Base acts_as_messageable end
You are not limited to the User model. You can use Mailboxer in any other model and use it in several different models. If you have ducks and cylons in your application and you want to exchange messages as if they were the same, just add
acts_as_messageable to each one and you will be able to send duck-duck, duck-cylon, cylon-duck and cylon-cylon messages. Of course, you can extend it for as many classes as you need.
class Duck < ActiveRecord::Base acts_as_messageable end
class Cylon < ActiveRecord::Base acts_as_messageable end
Version 0.8.0 sees
Messageable#unread renamed to
is_(un)read. This may break existing applications, but
read is a reserved name for Active Record, and the best pratice in this case is simply avoid using it.
#alfa wants to send a message to beta alfa.send_message(beta, "Body", "subject")
As a messageable, what you receive are receipts, which are associated with the message itself. You should retrieve your receipts for the conversation and get the message associated with them.
This is done this way because receipts save the information about the relation between messageable and the messages: is it read?, is it trashed?, etc.
#alfa gets the last conversation (chronologically, the first in the inbox) conversation = alfa.mailbox.inbox.first #alfa gets it receipts chronologically ordered. receipts = conversation.receipts_for alfa #using the receipts (i.e. in the view) receipts.each do |receipt| ... message = receipt.message read = receipt.is_unread? #or message.is_unread?(alfa) ... end
#alfa wants to reply to all in a conversation #using a receipt alfa.reply_to_all(receipt, "Reply body") #using a conversation alfa.reply_to_conversation(conversation, "Reply body")
#alfa wants to reply to the sender of a message (and ONLY the sender) #using a receipt alfa.reply_to_sender(receipt, "Reply body")
#delete conversations forever for one receipt (still in database) receipt.mark_as_deleted #you can mark conversation as deleted for one participant conversation.mark_as_deleted participant #Mark the object as deleted for messageable #Object can be: #* A Receipt #* A Conversation #* A Notification #* A Message #* An array with any of them alfa.mark_as_deleted conversation # get available message for specific user conversation.messages_for(alfa)
#alfa wants to retrieve all his conversations alfa.mailbox.conversations #A wants to retrieve his inbox alfa.mailbox.inbox #A wants to retrieve his sent conversations alfa.mailbox.sentbox #alfa wants to retrieve his trashed conversations alfa.mailbox.trash
You can use Kaminari to paginate the conversations as normal. Please, make sure you use the last version as mailboxer uses
select('DISTINCT conversations.*') which was not respected before Kaminari 0.12.4 according to its changelog. Working correctly on Kaminari 0.13.0.
#Paginating all conversations using :page parameter and 9 per page conversations = alfa.mailbox.conversations.page(params[:page]).per(9) #Paginating received conversations using :page parameter and 9 per page conversations = alfa.mailbox.inbox.page(params[:page]).per(9) #Paginating sent conversations using :page parameter and 9 per page conversations = alfa.mailbox.sentbox.page(params[:page]).per(9) #Paginating trashed conversations using :page parameter and 9 per page conversations = alfa.mailbox.trash.page(params[:page]).per(9)
You can take a look at the full documentation for Mailboxer in rubydoc.info.
If you need a GUI you should take a look at these links: