You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first integration method uses the sprockets asset pipeline to deliver the Angular app. This ability comes baked into Rails already and so no special configuration is needed to support Angular.
Advantages of the approach:
Zero configuration in Rails
Rendering of the Angular app only to Rails-based authenticated users
Rendering of custom data in the JavaScript files
Choice of using either CoffeeScript or JavaScript without changing workflow
Simultaneous Rails and Angular development
Inside of this approach, we'll do our work in the directories as follows:
vendor/assets/ - Our assets that we're loading from other authors, such as Twitter Bootstrap and custom Angular libraries
In order to set up our app to deliver Angular apps, we can:
Download and embed the necessary JavaScripts in our vendor/assets/ directory, or
Use the Rails angularjs-rails gem, which is a thin wrapper around the Angular libraries.
TIP: Include the ngmin-rails gem to take care of running the pre-minifier for us.
Feel free to include Twitter's Bootstrap or the Zurb Foundation gem:
# For Twitter's Bootstrapgem'bootstrap-sass-rails'# or for Zurb Foundationgem'zurb-foundation'
NOTE: If turbolinks is listed in your Gemfile, make sure you remove it. Turbolinks will affect the Angular app development, so it's just easier to not deal with the feature.
Building the share API
Bug: To get the application working as it was built up to this point you need to move the SharesController into app/controllers/api and rename it to Api::SharesController.
Bug: The create action is incorrect. See below for a working version:
defcreate# Not used# link = params[:url]share_params={from_user_id: current_user.id,url: params[:url]}# No such method on User called find_by_name_or_email # if to_user = User.find_by_name_or_email(params[:user])ifto_user=User.where("name = :name OR email = :email",{name: params[:user],email: params[:user]}).firstshare_params[:to_user_id]=to_user.idelseshare_params[:to_email]=params[:user]endshare=Share.create(share_params)renderstatus: 200,json: {success: share.persisted?,share_id: share.id}end