Jump to content

The ultimate community for Ruby on Rails developers.


Most Liked Content


#4 Welcome to the new Rails Forum

Posted by Adam on 14 August 2013 - 04:15 PM

When we launched Rails Forum in May 2006, Rails was just barely past 1.0. It was a fledgling framework with a head of steam, but not much widespread adoption. There weren't too many places to go for help outside of the official email lists -- even Stack Overflow was still two years away!

 

Once we opened the virtual doors to the forum, it was obvious immediately that it was filling a real need. An active community sprang up almost overnight, and grew to over 4,000 members and 24,000 posts in the first year. As Rails grew, so did the forum. 

 

Unfortunately, we didn't do a very good job of maintaining that community and it has been overrun by spam in recent years. That's unacceptable and we apologize for letting it happen. 

 

That's why today we're happy to announce that we're relaunching Rails Forum. We want the forum to get back to its roots. We want to be a useful resource that contributes positively to the Rails community again. We needed a clean slate. To that end, we've ported everything over to a more mature and secure software system, redesigned the site, and put in place a new moderation team.

 

Please pop in into the Introductions forum to say hello :)

 

We hope you'll join us and register for the new Rails Forum! Please don't hesitate to let us know if you have concerns or suggestions for serving you better.


  • midwire, kjetil, Jamie and 1 other like this


#132 CentOS vs Ubuntu Server

Posted by Tom on 14 August 2013 - 08:59 PM

BTW this question is why it's good to have a RailsForum. This question wouldn't survive 60 seconds without being closed on StackOverflow.


  • AstonJ, MrPepper, burmjohn and 1 other like this


#71263 Moderators Needed!

Posted by Adam on 24 February 2015 - 11:49 AM

Hi there,

 

We're looking some moderators to join the forum and help out with keeping SPAM at bay. If you've been around for a while and would be happy to delete a few SPAM posts when you're passing, that'd be great.

 

Please drop me an message on here if you'd like to help out :)

 

Many thanks,

Adam

 


  • jefflunt, Ohm and RubyNewbie like this


#6 Setting up desktop notifications with Rails & Noti

Posted by Adam on 14 August 2013 - 04:21 PM

This tutorial will guide you through how to set up desktop notifications within a Ruby on Rails application using Noti.

 

Noti is a web service which allows users to receive desktop notifications from any online application without the need for their browser to be open or them to be actively visiting your website. Any user who wishes to receive notifications will install a tiny native OS X, Windows or Linux desktop application and login using their own Noti username & password

 

Before your application can send notifications to a user you will need to ask them to "authorise" your application. This authorisation process will provide you with a unique token which you can use as an address when sending your notifications to their desktops.

 

Configuring for battle

 

Noti provides an easy to use RubyGem which provides all the core functionality you need to get started. To begin with we will need to load this gem into our Rails application's Gemfile. Open up your Gemfile and add the following line to the bottom:

gem 'noti'

Once you have added this and saved the file, you should run bundle install to install the dependency. If you haven't already signed up for a Noti account you should do this now and create a new application within the Noti website. When you have created this application, you will be provided with a token which you need to add into config/initializers/noti.rbas so:

Noti.app = '4842e7ad-1cc5-66bf-8e4b-a9ec7ac3b828'

Be sure you replace the token above with your own application's token. Once you've done this, be sure to restart your web server processes.

 

Get authorisation from your users

 

We will assume your application has a User model which you use to identify users who login to your application. It will be this model which stores the user's Noti "token". You will need to add a new string-formatted column to your users table called noti_token.

 

Now we need to populate this field with a token from the user. In order to do this, we must provide a link in our application so that our users can authorise our application to send them notifications. We will first create a new controller in our application which will be responsible for handling all of these authorisation actions.

rails generate controller NotiAuthorisations

Now we will create some routes in our config/routes.rb file which will point to our new controller. Open up this file and add the following 2 routes.

Notitest::Application.routes.draw do
  post 'noti' => 'noti_authorisations#new', :as => 'setup_noti'
  get 'noti/callback' => 'noti_authorisations#create', :as => 'noti_callback'
end

Now these routes are in place, we will go ahead and add some code to our new controller. Open up your newly created app/controllers/noti_authorisations_controller.rb file. This controller will consist of two methods:

  • new - this will initiate a new authorisation request. If a user wishes to authorise your application, you will send them to this action.
  • create - once a user has authorised your application with the Noti service, they will be returned to this action so we can finalise things.
class NotiAuthorisationsController < ApplicationController
  def new
    token = Noti::Token.create_request_token(noti_callback_url)
    session[:noti_rt] = token.request_token
    redirect_to token.redirect_url
  end

  def create
    token = Noti::Token.get_access_token(session[:noti_rt])
    current_user.update_attribute(:noti_token, token)
    session[:noti_rt] = nil
    redirect_to root_path, :flash => "Noti has now been configured for your account!"
  end
end

Now, lots of things happened there. Let's firstly look at the new method. This firstly requests a "request token" from the Noti API by sending a URL where the user should be returned to after they authorise your app. This returns an object which implemented two methods: request_token which contains the randomly generated token for this specific authorisation and redirect_url which is the URL which you must redirect the user to complete the authorisation. We use the first of these methods to set a session variable called :noti_rt and the second to redirect the user to the Noti website.

 

When the user is redirected they will be shown a message saying that you are requesting permission to send them notifications. They have the option to login or sign up for an account. Once they have completed one of these actions they will be redirected back to the URL specified when you generated the request token. If they sign up for an account, they will also be sent an email outlining how they should go about downloading the client software.

 

When the user is redirected, they will be sent to the create action we just wrote. This method uses the session variable we created earlier to ask Noti for a corresponding "access token" to go with the "request token". The token provided will be unique to the individual user and this must be stored along with their other information. This is the unique token used to send this user desktop notifications. This method now assumes that you have a current_user ActiveRecord instance for the currently logged in user and uses the update_attribute method to permanently store the user's Noti token. The final part of this action clears the session variable and redirects the user with a message alerting them to the fact their Noti account is now configured.

 

Of course, in order to start the authorisation process you will need to provide your users with a link to the 'new' action which we defined above. You can do this using a simple link_to method in one of your views:

link_to('Setup Desktop Notifications', setup_noti_path, :method => :post)

Finally, let's send a notification!

 

Now we have user's Noti tokens safely stored in our database, we can send them notifications! Yay!

Sending a notification is a very simple process and allows you as the application developer to choose a title, additional text, a sound as well an image to display with the notification. You can choose to send notifications from anywhere in your application but for this example, we will extend our NotiAuthorisationsController#create action to send a "welcome" notification when the user logs in.

notification = Noti::Notification.new
notification.title = "Notifications are ready to go!"
notification.text = "You will now receive application notifications directly to your desktop"
notification.sound = 'alert2'
notification.deliver_to(current_user.noti_token)

The last code block is pretty much all you need to know about sending notifications. Once you have created a notification object, you can use the deliver_to method to send the notification itself. This method accepts a user's Noti token as it's only parameter.

 

You may be wondering what sounds are available? A full list of sounds can be found in the Noti API documentation. You're probably best just experimenting to hear what each of these sound like.

 

And there you have it!

 

Congratulations - you now have desktop notifications in your web application! You may want to explore additional features like bulk-sending notifications and obtaining notification display statuses. Full details about these can be found in the Noti API docs or on the gem's Github page.


  • shorepound, CapRoR and Tom like this


#558 Best way to learn Rails?

Posted by AstonJ on 17 August 2013 - 10:23 PM

When I first started out, I asked that question a lot. I just wanted someone to say, look do this this and this, then this this and this - a bit like a step-by-step, but one that would work. I didn't find one, but did get to speak to lots of prominent Rails folk and took on-board their advice... and promised myself I would do such a guide for anyone else serious about learning Ruby and Rails.

 

So here it is: Best way to learn Rails I hope you enjoy it as much as I did!

 

(I'm not sure if it still is, but it used to be returned with the !Learn factoid in the official Rails chat room - just adding that in case you're wondering whether it's a good guide to follow or not)

 

Please feel free to add your own tips on learning Rails :)


  • Tom, MrPepper and patrickmaciel like this


#261 Tapatalk Support

Posted by Adam on 15 August 2013 - 10:59 AM

We've now added this :)

 

Enjoy.


  • Funnyvibe, Jamie and burmjohn like this


#225 Changes in Rails 4

Posted by Andre Dublin on 15 August 2013 - 02:10 AM

I've always liked using http://railsdiff.org/


  • BrockFredin, jefflunt and wilsonsilva like this


#1167 RSpec and using --no-test-framework?

Posted by Kelli Shaver on 09 September 2013 - 08:49 AM

I think writing tests could be useful, but probably not TDD for the reasons you mentioned (is it the app code, or is it the test that's breaking?). Code something, test it in your browser and see that it works, then write a test for it. I feel like it's a practical way to learn the workings of your testing framework of choice. 

 

Knowing how/what to test for and what makes a good test is another matter entirely. Check out http://betterspecs.org - there's some really good info there. 


  • Rowel, rayray and orrymr like this


#1003 How to add additional attributes to the join table in HABTM and fetch that wh...

Posted by Rowel on 03 September 2013 - 11:50 AM

And consider i need to add a field say type in the join table along with the reference where i need to add the type of the category.

 

I think you need to use has many :through  relationships instead of has_and_belongs_to_many  for your particular situation, since you need to also work on their relationship table.   

 

http://guides.rubyon...ion_basics.html

has_many_through.png


  • Kelli Shaver, james and Logesh like this


#6358 How to select all users except ids

Posted by Ohm on 27 October 2014 - 10:27 PM

If you have all the ids of the users you don't want in params[:ids] just use that

User.where.not(id: params[:ids])

  • pramod and Pinta777 like this


#6327 Time.now returns the server time or client time ?

Posted by Ohm on 15 October 2014 - 05:55 PM

Try it out. Launch a Rails console on the server and type:

Time.now

You'll get a result back like:

=> 2014-10-15 19:55:29 +0200

If you have configured your Rails app to a different timezone than the one it's located in (if you have e.g. an European app running on an server in the US) you'll need to use:

Time.zone.now

which will return a time like:

=> Wed, 15 Oct 2014 19:55:32 CEST +02:00
So, to answer the question: You'll (of course) get the server time back when running Time.now on the server.

  • Anuj Dubey and Pinta777 like this


#5685 How to make a connection between the models?

Posted by Ohm on 11 September 2014 - 08:23 PM

I think what you're looking for is single table inheritance (STI) which lets you create the following:

class Item < ActiveRecord::Base
  has_many :switches
end

class Switch < ActiveRecord::Base
  belongs_to :item
end

class Photo < Switch
end

class Store < Switch
end

If the Switch model has a type column, it'll use this to figure out which of the two Photo or Store that it'll use.

 

A normal use case would then be to add scopes to the Switch model:

...
scope :photos, -> { where(type: 'photo') }
scope :stores, -> { where(type: 'store') }
...

and then delegate to these scopes from the Item model:

...
delegate :photos, :stores, to: :assets
...

  • eViper and Anuj Dubey like this


#4114 adding searchablecolumns

Posted by Ohm on 26 July 2014 - 09:20 PM

You need to write the correct SQL for searching either in item_code or colour_description, using SQLs OR.

 

This can be done like so:

def self.search(search)
  if search
    where('item_code ILIKE :search OR colour_description LIKE :search', search: "%#{search}%")
  else
    scoped
  end
end

  • Jamie and DvDj like this


#4080 link_to with array parameter for URL : What does it mean?

Posted by Clint Bishop on 21 July 2014 - 02:47 AM

Hi!

 

The short answer to the question is: an array containing an Article of id 1 and a comment of id 2 will translate into this URL: /articles/1/comments/2.

 

I wrote a little more on the subject here: http://norobotdiving..._to-with-array/. Check it out!


  • Jamie and rovf like this


#3943 Advanced Tutorials

Posted by Jimbollu on 16 June 2014 - 01:31 PM

Hi All. I think I know pretty much everything there is to know about how to use Rails. 100% of the terminology. 

 

However, I struggle when it comes to making more complex sites. Why? Because the uncountable billions of tutorials I've watched/read are pretty basic, and all of them only briefly touch on ajax. 

 

If I were to read some advanced tutorials, I'm sure all of my knowledge would fall into place. However I can't find any! They're all basic, all introductory. Looking at the contents pages of so called 'advanced' books seem to imply the 'advanced' tutorials cover RESTful architecture and MVC, just stuff I know in my sleep.

 

I love learning from actual projects. Learning terminology or what aspects of rails are in isolation just doesn't help me at all. 

 

I want a huge, detailed tutorial on

  • How to build a forum
  • '' a social network (a real deal facebook-esque one)
  • '' videosharing site
  • An upload manager with upload bar (like on this site)
  • '' a file conversion site (Although maybe Rails isn't the framework for that)
  • " A github clone. (Gitlab is already on RoR)
  • " A CMS
  • ... as well as vast and intricate control panels for all of these things. A control panel like this:

Screenshot from 2014-06-16 14:10:33.png

 

I assume we'd use AJAX requests and JSON routes to retrieve this information, but I've yet to see a tutorial, and I have no idea how the javascript would look. And I'm fed up of using my intuition only to realise I've wasted weeks and I've been barking up the wrong tree. I mean I say AJAX and JSON, but maybe websockets should be used instead. I need guidance on how to use my knowledge, not pure knowledge.

 

Some of this may be more Javascript rather than Rails, but even so Rails is deeply involved in all of my ideas and I can't believe how sparse the resources are out there. 

 

This site:

 

http://www.bet365.co...?&cb=1088078198

 

Appears to use some ungodly union of ASP and Flash (based on the URL, nothing more), but I'd love to be able to create something like this with Rails and AJAX (only as a practise project). I'm sure I could give it a very good try, but I'm concerned that by the end I'll either have a poorly-organised project / halfway through I'll have to scrap everything because I've realised there's a far better way to do things.

 

Apologies if I sound annoyed it's just I've been the last 4 months looking for advanced tutorials and just now I've just snapped because there is NOTHING. 


  • Jimbollu and ahnbizcad like this


#3777 One-line loop in a view

Posted by Ohm on 15 May 2014 - 11:12 AM

If what you really wanted was 01234567, you could do it like this

<%= 8.times.to_a.join %>

if you want the space between them supply the #join method with a space.


  • Jamie and arnig1981 like this


#3069 Rails installation on windows

Posted by jack on 24 February 2014 - 09:45 AM

Mint with Cinnamon is wonderful. Personally I still use Ubuntu, but I have no real reason to prefer either. It is very rare that I ever need the GUI, as most of what I do is terminal based.


  • james and dailammoc like this


#2418 Add Ruby and make it default code highlighting language

Posted by Ohm on 22 December 2013 - 08:10 PM

When I use the code block it makes code like

this

however I can only choose PHP, Javascript, HTML, SQL, CSS, XML, and none. Why can't I choose Ruby? And why aren't Ruby the default?


  • jack and james like this


#21064 PHP Mobile phone SMS payment system in Ruby on Rails

Posted by Ohm on 24 November 2014 - 09:16 PM

I'm sorry to have to do this, but:

 

Hell-NO-GIF.gif


  • Linards and zachariastr like this


#1839 newbie question

Posted by Ohm on 31 October 2013 - 06:11 AM

Variables with a : before them are symbols

:symbol

Think of these like constants.

 

When working with hashes, you'll see stuff like

hash = { :key => 'value' }

Here the symbols are used as keys. In Ruby 1.9 they introduced a shorthand for the above, namely

hash = { key: 'value' }

which is the same way Javascript defines objects and hashes.


  • james and Rowel like this