Skip to content

ycchen/mobile-demo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

This README would normally document whatever steps are necessary to get the application up and running.

Things you may want to cover:

  • Ruby version

  • System dependencies

  • Configuration

  • Database creation

  • Database initialization

  • How to run the test suite

  • Services (job queues, cache servers, search engines, etc.)

  • Deployment instructions

Please feel free to use a different markup language if you do not plan to run rake doc:app.

# Generate User model use ‘devise’ gem

  1. run the generator

$ rails generate devise:install

  1. generate user model

$ rails generate devise User

# generate registrations_controller.rb $ rails g controller registrations index

# generate devise views files $ rails g devise:views devise

# Generate Users controller $ rails g controller Users index new create edit update destroy

# Adding upload file with carrierwave gem github.com/carrierwaveuploader/carrierwave/wiki

  1. start off by generating an uploader:

$ rails generate uploader file # this will created app/uploaders/file_uploader.rb

Multiple files upload with carrierwave and nested_form

# add nested_form to Gemfile gem ‘nested_form’

# install nested_form $ rails g nested_form:install

# updated assetsjavascriptsapplication.js to add nested_form js //= require jquery_nested_form

# Generate picture model $ rails g model picture attachable:references file:string

# Updated migration script to add :polymorphic => true on picture model class CreatePictures < ActiveRecord::Migration

def change
  create_table :pictures do |t|
    t.references :attachable, index: true, :polymorphic => true
    t.string :file

    t.timestamps
  end
end

end

$ rake db:migrate

Generate Images model

$ rails g scaffold image name:string location:string latitude:decimal longitude:decimal

Update relationship between image and picture models

–modelimage.rb has_many :pictures, :as => :attachable, :dependent => :destroy accepts_nested_attributes_for :pictures, :allow_destroy => true

–modelpicture.rb

belongs_to :attachable, polymorphic: true
mount_uploader :file FileUploader

## Update controllersimage.rb image_params method added :pictures_attributes => [:id, :file, ‘_destroy’] to the permit()

## Modified viewsimages_form.html.erb to include upload form

## problem with carrierwave not able to upload with jquery mobile ## stackoverflow.com/questions/16815569/rails-file-field-does-not-upload-anything –OK after spending hours on the matter, the problem is that jQuery Mobile submits forms with Ajax by default, and files cannnot be submitted with Ajax without using plugins etc. So the solution is to disable the Ajax like this:

form_for(@business_profile, :url => business_profile_path, :validate => true, :html => { :‘data-ajax’ => false }) do |f|