Squadly Dev Post #2, Adding Events

So our UI is taking a little longer than we thought but we have added events for users. Will be adding info and corrections to this as I remember/see them, sorry if there are inacurracies.

Creating the event model:

An event has three fields (for now): a name, location, and message. They are of type string, string, and text, respectively.

We did some scaffolding to generate the model: rails generate model event name:string location:string message:text user:references

Setting up Associations

As it stands, a user has many events attached to it while an event can only be owned by one person. We needed to implement this in the back end where an event would have a foreign key to a user record named user_id. The user:preferences line does just this.

Rails also provides some very convenient features for relationships like this. In the app/models directory, editing the event.rb file to include the line belongs_to :user, then editing the user.rb file to include has_many enables us to do a couple of things.

Setting up Routes

The routes for an event is nested within a user's route block so that the link looks like /user/*user id*/events/*event_id*. At this point at least when a user views their event, it should be coming from their page. Since we'd like the ability for users to have a feed of other users' events, we might forgo this route altogether and just have something like /events/*id*

Routes can become extremely complicated. For a detailed guide here's an official guide from Rails, Rails Routing from the Outside In.

What's Next

After setting up the backend, frontend, and tweaking application logic, core functionality is pretty much complete.

  • Front end implementation
  • API research


Including namespaced routes in controllers and views - I believe you just simply add path to the end.

Passing arguments in Rails via redirect_to


https://agilewarrior.wordpress.com/2014/04/16/how-to-specify-controller-and-action-in-rails-form/ https://agilewarrior.wordpress.com/2011/09/10/difference-between-formfor-and-formtag-helper-tags-in-rails/