').append(availableLocales))
56 |
57 | # Handle locale addition
58 | $addLocaleButton.find('ul a').click (e) ->
59 | href = $(this).attr('href')
60 | $tab = $tabs.filter('[href="' + href + '"]')
61 | toggleTab($tab, true)
62 | $tab.click()
63 | updateLocaleButtonsStatus($dom)
64 | e.preventDefault()
65 |
66 | # Remove a locale from the tab.
67 | $removeButton = $('x').click (e) ->
68 | e.stopImmediatePropagation()
69 | e.preventDefault()
70 | $tab = $(this).parent()
71 | toggleTab($tab, false)
72 | if $tab.hasClass('active')
73 | $tabs.not('.hidden').eq(0).click()
74 |
75 | updateLocaleButtonsStatus($dom)
76 |
77 | # Add the remove button to every tab.
78 | $tabs.not('.default').append($removeButton)
79 |
80 | # Add the new button at the end of the locale list.
81 | $dom.append($addLocaleButton)
82 |
83 | $tabs.each ->
84 | $tab = $(@)
85 | $content = $contents.filter($tab.attr("href"))
86 | containsErrors = $content.find(".input.error").length > 0
87 | $tab.toggleClass("error", containsErrors)
88 | # Find those tabs that are in use.
89 | hide = true
90 | # We will not hide the tabs that have any error.
91 | if $tab.hasClass('error') || $tab.hasClass('default')
92 | hide = false
93 | else
94 | # Check whether the input fields are empty or not.
95 | $content.find('[name]').not('[type="hidden"]').each ->
96 | if $(this).val()
97 | # We will not hide the tab because it has some data.
98 | hide = false
99 | return false
100 |
101 | if hide
102 | toggleTab($tab, false)
103 | else
104 | toggleTab($tab, true)
105 |
106 | # Remove the fields of hidden locales before form submission.
107 | $form = $dom.parents('form')
108 | if !$form.data('ready')
109 | $form.data('ready')
110 | $form.submit ->
111 | # Get all translations (the nested ones too).
112 | $('.activeadmin-translations > ul').each ->
113 | # Get the corresponding fieldsets.
114 | $fieldsets = $(this).siblings('fieldset')
115 | $("li:not(.add-locale) > a", this).each ->
116 | # Remove them if the locale is hidden.
117 | if $(this).hasClass('hidden')
118 | # check if it's an existing translation otherwise remove it
119 | $currentFieldset = $("fieldset#{$(this).attr('href')}")
120 | $translationId = $('input[id$=_id]', $currentFieldset)
121 | if $translationId.val()
122 | # mark it for database removal appending a _destroy element
123 | $destroy = $('').attr(
124 | type: 'hidden',
125 | name: $translationId.attr('name').replace('[id]', '[_destroy]'),
126 | id: $translationId.attr('id').replace('_id', '_destroy'),
127 | value: '1'
128 | )
129 | $destroy.appendTo($currentFieldset)
130 | else
131 | # remove the fieldset from dom so it won't be submitted
132 | $fieldsets.filter($(this).attr('href')).remove()
133 |
134 | #Initially update the buttons' status
135 | updateLocaleButtonsStatus($dom)
136 | $tabs.filter('.default').click()
137 |
138 | # this is to handle elements created with has_many
139 | $("a").bind "click", ->
140 | setTimeout(
141 | -> translations()
142 | 50
143 | )
144 |
145 | # Used to toggle translations values for inline fields
146 | $('a.ui-translation-trigger').click (e) ->
147 | $locale = $(this).data('locale')
148 | $td = $(this).closest('td')
149 | $('.field-translation', $td).hide()
150 | $(".locale-#{$locale}", $td).show()
151 | $(this).parent().children('a.ui-translation-trigger').removeClass('active')
152 | $(this).addClass('active')
153 | e.preventDefault()
154 |
155 | translations()
156 |
--------------------------------------------------------------------------------
/lib/active_admin/globalize/attributes_table_extension.rb:
--------------------------------------------------------------------------------
1 | require 'active_admin/views/components/attributes_table.rb'
2 |
3 | module ActiveAdmin
4 | module Views
5 |
6 | # Provide additional method #translated_row to attribute table
7 | class AttributesTable < ActiveAdmin::Component
8 |
9 | # Show a row with their translations and selectors for choosing locale to show.
10 | #
11 | # If a block is given it will be used to format the translation,
12 | # otherwise field taken from translation object is used as translation.
13 | #
14 | # Additional options are forwarded to the original row call.
15 | #
16 | # @overload translated_row(field, opts)
17 | # @param [String] field row label, also used as field name if none given in options
18 | # @param [Hash] opts the options to create a message with.
19 | # @option opts [String] :field field to retrieve from model if different from first argument of args
20 | # @option opts [String] :locale (I18n.locale) initial locale to show in the ui
21 | # @option opts [Boolean] :inline (true) if true locale selectors (and values) are shown inline,
22 | # otherwise as block content and tabs
23 | #
24 | # @yield if given will be used to build single translations
25 | # @yieldparam [*::Translation] Globalize translation model
26 | # @yieldreturn [String] content to show as translation
27 | #
28 | # @example Show inlined translation values for title field
29 | # show do |p|
30 | # attributes_table do
31 | # translated_row(:title)
32 | # end
33 | # end
34 | #
35 | # @example Show block translation for body field with selection of initial locale
36 | # show do |p|
37 | # attributes_table do
38 | # translated_row(:body, inline: false, locale: :es)
39 | # end
40 | # end
41 | #
42 | def translated_row(*args, &block)
43 | options = args.extract_options!
44 | options.reverse_merge!(inline: true, locale: I18n.locale)
45 | field = options[:field] || args.first
46 | raise ArgumentError, "Field '#{field}' is not translatable" unless translatable?(field)
47 | # Remove my options from passed options
48 | row_options = options.symbolize_keys.except(:field, :locale, :inline)
49 | # Append remaining options to original args
50 | args.push(row_options) unless row_options.empty?
51 | # Render the table row with translations
52 | row(*args) do
53 | if options[:inline]
54 | ''.html_safe.tap do |value|
55 | # Add selectors for inline locale
56 | value << inline_locale_selectors(field, options[:locale], &block)
57 | # Build translations spans
58 | value << field_translations(field, :span, options[:locale], &block)
59 | end
60 | else
61 | content_tag(:div, class: 'activeadmin-translations') do
62 | ''.html_safe.tap do |value|
63 | # Render selectors as in translation ui
64 | value << block_locale_selectors(field, options[:locale], &block)
65 | # Build translations divs for actual translations
66 | value << field_translations(field, :div, options[:locale], &block)
67 | end
68 | end
69 | end
70 | end
71 | end
72 |
73 | private
74 |
75 | # @return [Boolean] true iff the field is translatable
76 | def translatable?(field)
77 | @resource_class.translates? &&
78 | @resource_class.translated_attribute_names.include?(field.to_sym)
79 | end
80 |
81 | # Build a tag for each field translation with appropriate css classes to make javascript working
82 | # @param [String] field field name to render
83 | # @param [Symbol] tag tag to enclose field translation
84 | # @param [Symbol] initial_locale locale to set as not hidden
85 | def field_translations(field, tag, initial_locale, &block)
86 | available_translations.map do |translation|
87 | # Classes for translation span only first element is visible
88 | css_classes = ['field-translation', "locale-#{translation.locale}"]
89 | # Initially only element for selected locale is visible
90 | css_classes.push 'hidden' unless translation.locale == initial_locale.to_sym
91 | # Build content for cell or div using translation locale and given block
92 | content = field_translation_value(translation, field, &block)
93 | # return element
94 | if tag == :span # inline element
95 | # attach class to span if inline
96 | css_classes.push('empty') if content.blank?
97 | content_tag(tag, content.presence || 'Empty', class: css_classes)
98 | else
99 | # block content
100 | content_tag(tag, class: css_classes) do
101 | # Return content or empty span
102 | content.presence || content_tag(:span, 'Empty', class: 'empty')
103 | end
104 | end
105 | end.join(' ').html_safe
106 | end
107 |
108 | def block_locale_selectors(field, initial_locale, &block)
109 | content_tag(:ul, class: 'available-locales locale-selector') do
110 | available_translations.map do |translation|
111 | css_classes = ['translation-tab']
112 | css_classes << 'active' if translation.locale == initial_locale.to_sym
113 | css_classes << 'empty' unless content.presence
114 | content_tag(:li, class: css_classes) do
115 | I18n.with_locale(translation.locale) do
116 | default = 'default' if translation.locale == initial_locale.to_sym
117 | content_tag(:a, I18n.t(:"active_admin.globalize.language.#{translation.locale}"), href: ".locale-#{translation.locale}", class: default)
118 | end
119 | end
120 | end.join.html_safe
121 | end
122 | end
123 |
124 | # Return flag elements to show the given locale using javascript
125 | def inline_locale_selectors(field, initial_locale, &block)
126 | content_tag(:span, class: 'inline-locale-selector') do
127 | available_translations.map do |translation|
128 | content = field_translation_value(translation, field, &block)
129 | css_classes = ['ui-translation-trigger']
130 | css_classes << 'active' if translation.locale == initial_locale.to_sym
131 | css_classes << 'empty' unless content.presence
132 | # Build a link to show the given translation
133 | link_to(flag_icon(translation.locale), '#', class: css_classes, data: {locale: translation.locale})
134 | end.join(' ').html_safe
135 | end
136 | end
137 |
138 | def available_translations
139 | @record_translations ||= @collection.first.translations.order(:locale)
140 | end
141 |
142 | def field_translation_value(translation, field)
143 | I18n.with_locale(translation.locale) do
144 | block_given? ? yield(translation) : translation.send(field)
145 | end
146 | end
147 | end
148 | end
149 | end
150 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/active_admin.rb:
--------------------------------------------------------------------------------
1 | ActiveAdmin.setup do |config|
2 |
3 | # == Site Title
4 | #
5 | # Set the title that is displayed on the main layout
6 | # for each of the active admin pages.
7 | #
8 | config.site_title = "Dummy"
9 |
10 | # Set the link url for the title. For example, to take
11 | # users to your main site. Defaults to no link.
12 | #
13 | # config.site_title_link = "/"
14 |
15 | # Set an optional image to be displayed for the header
16 | # instead of a string (overrides :site_title)
17 | #
18 | # Note: Aim for an image that's 21px high so it fits in the header.
19 | #
20 | # config.site_title_image = "logo.png"
21 |
22 | # == Default Namespace
23 | #
24 | # Set the default namespace each administration resource
25 | # will be added to.
26 | #
27 | # eg:
28 | # config.default_namespace = :hello_world
29 | #
30 | # This will create resources in the HelloWorld module and
31 | # will namespace routes to /hello_world/*
32 | #
33 | # To set no namespace by default, use:
34 | # config.default_namespace = false
35 | #
36 | # Default:
37 | # config.default_namespace = :admin
38 | #
39 | # You can customize the settings for each namespace by using
40 | # a namespace block. For example, to change the site title
41 | # within a namespace:
42 | #
43 | # config.namespace :admin do |admin|
44 | # admin.site_title = "Custom Admin Title"
45 | # end
46 | #
47 | # This will ONLY change the title for the admin section. Other
48 | # namespaces will continue to use the main "site_title" configuration.
49 |
50 | # == User Authentication
51 | #
52 | # Active Admin will automatically call an authentication
53 | # method in a before filter of all controller actions to
54 | # ensure that there is a currently logged in admin user.
55 | #
56 | # This setting changes the method which Active Admin calls
57 | # within the application controller.
58 | config.authentication_method = :authenticate_admin_user!
59 |
60 | # == User Authorization
61 | #
62 | # Active Admin will automatically call an authorization
63 | # method in a before filter of all controller actions to
64 | # ensure that there is a user with proper rights. You can use
65 | # CanCanAdapter or make your own. Please refer to documentation.
66 | # config.authorization_adapter = ActiveAdmin::CanCanAdapter
67 |
68 | # You can customize your CanCan Ability class name here.
69 | # config.cancan_ability_class = "Ability"
70 |
71 | # You can specify a method to be called on unauthorized access.
72 | # This is necessary in order to prevent a redirect loop which happens
73 | # because, by default, user gets redirected to Dashboard. If user
74 | # doesn't have access to Dashboard, he'll end up in a redirect loop.
75 | # Method provided here should be defined in application_controller.rb.
76 | # config.on_unauthorized_access = :access_denied
77 |
78 | # == Current User
79 | #
80 | # Active Admin will associate actions with the current
81 | # user performing them.
82 | #
83 | # This setting changes the method which Active Admin calls
84 | # (within the application controller) to return the currently logged in user.
85 | config.current_user_method = :current_admin_user
86 |
87 |
88 | # == Logging Out
89 | #
90 | # Active Admin displays a logout link on each screen. These
91 | # settings configure the location and method used for the link.
92 | #
93 | # This setting changes the path where the link points to. If it's
94 | # a string, the strings is used as the path. If it's a Symbol, we
95 | # will call the method to return the path.
96 | #
97 | # Default:
98 | config.logout_link_path = :destroy_admin_user_session_path
99 |
100 | # This setting changes the http method used when rendering the
101 | # link. For example :get, :delete, :put, etc..
102 | #
103 | # Default:
104 | # config.logout_link_method = :get
105 |
106 |
107 | # == Root
108 | #
109 | # Set the action to call for the root path. You can set different
110 | # roots for each namespace.
111 | #
112 | # Default:
113 | # config.root_to = 'dashboard#index'
114 |
115 |
116 | # == Admin Comments
117 | #
118 | # This allows your users to comment on any resource registered with Active Admin.
119 | #
120 | # You can completely disable comments:
121 | # config.allow_comments = false
122 | #
123 | # You can disable the menu item for the comments index page:
124 | # config.show_comments_in_menu = false
125 | #
126 | # You can change the name under which comments are registered:
127 | # config.comments_registration_name = 'AdminComment'
128 |
129 |
130 | # == Batch Actions
131 | #
132 | # Enable and disable Batch Actions
133 | #
134 | config.batch_actions = true
135 |
136 |
137 | # == Controller Filters
138 | #
139 | # You can add before, after and around filters to all of your
140 | # Active Admin resources and pages from here.
141 | #
142 | # config.before_filter :do_something_awesome
143 |
144 |
145 | # == Setting a Favicon
146 | #
147 | # config.favicon = '/assets/favicon.ico'
148 |
149 |
150 | # == Removing Breadcrumbs
151 | #
152 | # Breadcrumbs are enabled by default. You can customize them for individual
153 | # resources or you can disable them globally from here.
154 | #
155 | # config.breadcrumb = false
156 |
157 |
158 | # == Register Stylesheets & Javascripts
159 | #
160 | # We recommend using the built in Active Admin layout and loading
161 | # up your own stylesheets / javascripts to customize the look
162 | # and feel.
163 | #
164 | # To load a stylesheet:
165 | # config.register_stylesheet 'my_stylesheet.css'
166 | #
167 | # You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
168 | # config.register_stylesheet 'my_print_stylesheet.css', :media => :print
169 | #
170 | # To load a javascript file:
171 | # config.register_javascript 'my_javascript.js'
172 |
173 |
174 | # == CSV options
175 | #
176 | # Set the CSV builder separator
177 | # config.csv_options = { :col_sep => ';' }
178 | #
179 | # Force the use of quotes
180 | # config.csv_options = { :force_quotes => true }
181 |
182 |
183 | # == Menu System
184 | #
185 | # You can add a navigation menu to be used in your application, or configure a provided menu
186 | #
187 | # To change the default utility navigation to show a link to your website & a logout btn
188 | #
189 | # config.namespace :admin do |admin|
190 | # admin.build_menu :utility_navigation do |menu|
191 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
192 | # admin.add_logout_button_to_menu menu
193 | # end
194 | # end
195 | #
196 | # If you wanted to add a static menu item to the default menu provided:
197 | #
198 | # config.namespace :admin do |admin|
199 | # admin.build_menu :default do |menu|
200 | # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
201 | # end
202 | # end
203 |
204 |
205 | # == Download Links
206 | #
207 | # You can disable download links on resource listing pages,
208 | # or customize the formats shown per namespace/globally
209 | #
210 | # To disable/customize for the :admin namespace:
211 | #
212 | # config.namespace :admin do |admin|
213 | #
214 | # # Disable the links entirely
215 | # admin.download_links = false
216 | #
217 | # # Only show XML & PDF options
218 | # admin.download_links = [:xml, :pdf]
219 | #
220 | # # Enable/disable the links based on block
221 | # # (for example, with cancan)
222 | # admin.download_links = proc { can?(:view_download_links) }
223 | #
224 | # end
225 |
226 |
227 | # == Pagination
228 | #
229 | # Pagination is enabled by default for all resources.
230 | # You can control the default per page count for all resources here.
231 | #
232 | # config.default_per_page = 30
233 |
234 |
235 | # == Filters
236 | #
237 | # By default the index screen includes a “Filters” sidebar on the right
238 | # hand side with a filter for each attribute of the registered model.
239 | # You can enable or disable them for all resources here.
240 | #
241 | # config.filters = true
242 |
243 | end
244 |
--------------------------------------------------------------------------------
/spec/dummy/README.rdoc:
--------------------------------------------------------------------------------
1 | == Welcome to Rails
2 |
3 | Rails is a web-application framework that includes everything needed to create
4 | database-backed web applications according to the Model-View-Control pattern.
5 |
6 | This pattern splits the view (also called the presentation) into "dumb"
7 | templates that are primarily responsible for inserting pre-built data in between
8 | HTML tags. The model contains the "smart" domain objects (such as Account,
9 | Product, Person, Post) that holds all the business logic and knows how to
10 | persist themselves to a database. The controller handles the incoming requests
11 | (such as Save New Account, Update Product, Show Post) by manipulating the model
12 | and directing data to the view.
13 |
14 | In Rails, the model is handled by what's called an object-relational mapping
15 | layer entitled Active Record. This layer allows you to present the data from
16 | database rows as objects and embellish these data objects with business logic
17 | methods. You can read more about Active Record in
18 | link:files/vendor/rails/activerecord/README.html.
19 |
20 | The controller and view are handled by the Action Pack, which handles both
21 | layers by its two parts: Action View and Action Controller. These two layers
22 | are bundled in a single package due to their heavy interdependence. This is
23 | unlike the relationship between the Active Record and Action Pack that is much
24 | more separate. Each of these packages can be used independently outside of
25 | Rails. You can read more about Action Pack in
26 | link:files/vendor/rails/actionpack/README.html.
27 |
28 |
29 | == Getting Started
30 |
31 | 1. At the command prompt, create a new Rails application:
32 | rails new myapp (where myapp is the application name)
33 |
34 | 2. Change directory to myapp and start the web server:
35 | cd myapp; rails server (run with --help for options)
36 |
37 | 3. Go to http://localhost:3000/ and you'll see:
38 | "Welcome aboard: You're riding Ruby on Rails!"
39 |
40 | 4. Follow the guidelines to start developing your application. You can find
41 | the following resources handy:
42 |
43 | * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44 | * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45 |
46 |
47 | == Debugging Rails
48 |
49 | Sometimes your application goes wrong. Fortunately there are a lot of tools that
50 | will help you debug it and get it back on the rails.
51 |
52 | First area to check is the application log files. Have "tail -f" commands
53 | running on the server.log and development.log. Rails will automatically display
54 | debugging and runtime information to these files. Debugging info will also be
55 | shown in the browser on requests from 127.0.0.1.
56 |
57 | You can also log your own messages directly into the log file from your code
58 | using the Ruby logger class from inside your controllers. Example:
59 |
60 | class WeblogController < ActionController::Base
61 | def destroy
62 | @weblog = Weblog.find(params[:id])
63 | @weblog.destroy
64 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65 | end
66 | end
67 |
68 | The result will be a message in your log file along the lines of:
69 |
70 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71 |
72 | More information on how to use the logger is at http://www.ruby-doc.org/core/
73 |
74 | Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75 | several books available online as well:
76 |
77 | * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79 |
80 | These two books will bring you up to speed on the Ruby language and also on
81 | programming in general.
82 |
83 |
84 | == Debugger
85 |
86 | Debugger support is available through the debugger command when you start your
87 | Mongrel or WEBrick server with --debugger. This means that you can break out of
88 | execution at any point in the code, investigate and change the model, and then,
89 | resume execution! You need to install ruby-debug to run the server in debugging
90 | mode. With gems, use sudo gem install ruby-debug. Example:
91 |
92 | class WeblogController < ActionController::Base
93 | def index
94 | @posts = Post.all
95 | debugger
96 | end
97 | end
98 |
99 | So the controller will accept the action, run the first line, then present you
100 | with a IRB prompt in the server window. Here you can do things like:
101 |
102 | >> @posts.inspect
103 | => "[#nil, "body"=>nil, "id"=>"1"}>,
105 | #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107 | >> @posts.first.title = "hello from a debugger"
108 | => "hello from a debugger"
109 |
110 | ...and even better, you can examine how your runtime objects actually work:
111 |
112 | >> f = @posts.first
113 | => #nil, "body"=>nil, "id"=>"1"}>
114 | >> f.
115 | Display all 152 possibilities? (y or n)
116 |
117 | Finally, when you're ready to resume execution, you can enter "cont".
118 |
119 |
120 | == Console
121 |
122 | The console is a Ruby shell, which allows you to interact with your
123 | application's domain model. Here you'll have all parts of the application
124 | configured, just like it is when the application is running. You can inspect
125 | domain models, change values, and save to the database. Starting the script
126 | without arguments will launch it in the development environment.
127 |
128 | To start the console, run rails console from the application
129 | directory.
130 |
131 | Options:
132 |
133 | * Passing the -s, --sandbox argument will rollback any modifications
134 | made to the database.
135 | * Passing an environment name as an argument will load the corresponding
136 | environment. Example: rails console production.
137 |
138 | To reload your controllers and models after launching the console run
139 | reload!
140 |
141 | More information about irb can be found at:
142 | link:http://www.rubycentral.org/pickaxe/irb.html
143 |
144 |
145 | == dbconsole
146 |
147 | You can go to the command line of your database directly through rails
148 | dbconsole. You would be connected to the database with the credentials
149 | defined in database.yml. Starting the script without arguments will connect you
150 | to the development database. Passing an argument will connect you to a different
151 | database, like rails dbconsole production. Currently works for MySQL,
152 | PostgreSQL and SQLite 3.
153 |
154 | == Description of Contents
155 |
156 | The default directory structure of a generated Ruby on Rails application:
157 |
158 | |-- app
159 | | |-- assets
160 | | | |-- images
161 | | | |-- javascripts
162 | | | `-- stylesheets
163 | | |-- controllers
164 | | |-- helpers
165 | | |-- mailers
166 | | |-- models
167 | | `-- views
168 | | `-- layouts
169 | |-- config
170 | | |-- environments
171 | | |-- initializers
172 | | `-- locales
173 | |-- db
174 | |-- doc
175 | |-- lib
176 | | |-- assets
177 | | `-- tasks
178 | |-- log
179 | |-- public
180 | |-- script
181 | |-- test
182 | | |-- fixtures
183 | | |-- functional
184 | | |-- integration
185 | | |-- performance
186 | | `-- unit
187 | |-- tmp
188 | | `-- cache
189 | | `-- assets
190 | `-- vendor
191 | |-- assets
192 | | |-- javascripts
193 | | `-- stylesheets
194 | `-- plugins
195 |
196 | app
197 | Holds all the code that's specific to this particular application.
198 |
199 | app/assets
200 | Contains subdirectories for images, stylesheets, and JavaScript files.
201 |
202 | app/controllers
203 | Holds controllers that should be named like weblogs_controller.rb for
204 | automated URL mapping. All controllers should descend from
205 | ApplicationController which itself descends from ActionController::Base.
206 |
207 | app/models
208 | Holds models that should be named like post.rb. Models descend from
209 | ActiveRecord::Base by default.
210 |
211 | app/views
212 | Holds the template files for the view that should be named like
213 | weblogs/index.html.erb for the WeblogsController#index action. All views use
214 | eRuby syntax by default.
215 |
216 | app/views/layouts
217 | Holds the template files for layouts to be used with views. This models the
218 | common header/footer method of wrapping views. In your views, define a layout
219 | using the layout :default and create a file named default.html.erb.
220 | Inside default.html.erb, call <% yield %> to render the view using this
221 | layout.
222 |
223 | app/helpers
224 | Holds view helpers that should be named like weblogs_helper.rb. These are
225 | generated for you automatically when using generators for controllers.
226 | Helpers can be used to wrap functionality for your views into methods.
227 |
228 | config
229 | Configuration files for the Rails environment, the routing map, the database,
230 | and other dependencies.
231 |
232 | db
233 | Contains the database schema in schema.rb. db/migrate contains all the
234 | sequence of Migrations for your schema.
235 |
236 | doc
237 | This directory is where your application documentation will be stored when
238 | generated using rake doc:app
239 |
240 | lib
241 | Application specific libraries. Basically, any kind of custom code that
242 | doesn't belong under controllers, models, or helpers. This directory is in
243 | the load path.
244 |
245 | public
246 | The directory available for the web server. Also contains the dispatchers and the
247 | default HTML files. This should be set as the DOCUMENT_ROOT of your web
248 | server.
249 |
250 | script
251 | Helper scripts for automation and generation.
252 |
253 | test
254 | Unit and functional tests along with fixtures. When using the rails generate
255 | command, template test files will be generated for you and placed in this
256 | directory.
257 |
258 | vendor
259 | External libraries that the application depends on. Also includes the plugins
260 | subdirectory. If the app has frozen rails, those gems also go here, under
261 | vendor/rails/. This directory is in the load path.
262 |
--------------------------------------------------------------------------------
/spec/dummy/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | # Use this hook to configure devise mailer, warden hooks and so forth.
2 | # Many of these configuration options can be set straight in your model.
3 | Devise.setup do |config|
4 | # The secret key used by Devise. Devise uses this key to generate
5 | # random tokens. Changing this key will render invalid all existing
6 | # confirmation, reset password and unlock tokens in the database.
7 | config.secret_key = '00adee3d99b3b7a8fa75b27911a7ce14e677fa4570d04f301791bf40ca901c6370ec96ab95cb4426887bb1f5040888abaa460f59198754fd76ef17863bf9fcb9'
8 |
9 | # ==> Mailer Configuration
10 | # Configure the e-mail address which will be shown in Devise::Mailer,
11 | # note that it will be overwritten if you use your own mailer class
12 | # with default "from" parameter.
13 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
14 |
15 | # Configure the class responsible to send e-mails.
16 | # config.mailer = 'Devise::Mailer'
17 |
18 | # ==> ORM configuration
19 | # Load and configure the ORM. Supports :active_record (default) and
20 | # :mongoid (bson_ext recommended) by default. Other ORMs may be
21 | # available as additional gems.
22 | require 'devise/orm/active_record'
23 |
24 | # ==> Configuration for any authentication mechanism
25 | # Configure which keys are used when authenticating a user. The default is
26 | # just :email. You can configure it to use [:username, :subdomain], so for
27 | # authenticating a user, both parameters are required. Remember that those
28 | # parameters are used only when authenticating and not when retrieving from
29 | # session. If you need permissions, you should implement that in a before filter.
30 | # You can also supply a hash where the value is a boolean determining whether
31 | # or not authentication should be aborted when the value is not present.
32 | # config.authentication_keys = [ :email ]
33 |
34 | # Configure parameters from the request object used for authentication. Each entry
35 | # given should be a request method and it will automatically be passed to the
36 | # find_for_authentication method and considered in your model lookup. For instance,
37 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
38 | # The same considerations mentioned for authentication_keys also apply to request_keys.
39 | # config.request_keys = []
40 |
41 | # Configure which authentication keys should be case-insensitive.
42 | # These keys will be downcased upon creating or modifying a user and when used
43 | # to authenticate or find a user. Default is :email.
44 | config.case_insensitive_keys = [ :email ]
45 |
46 | # Configure which authentication keys should have whitespace stripped.
47 | # These keys will have whitespace before and after removed upon creating or
48 | # modifying a user and when used to authenticate or find a user. Default is :email.
49 | config.strip_whitespace_keys = [ :email ]
50 |
51 | # Tell if authentication through request.params is enabled. True by default.
52 | # It can be set to an array that will enable params authentication only for the
53 | # given strategies, for example, `config.params_authenticatable = [:database]` will
54 | # enable it only for database (email + password) authentication.
55 | # config.params_authenticatable = true
56 |
57 | # Tell if authentication through HTTP Auth is enabled. False by default.
58 | # It can be set to an array that will enable http authentication only for the
59 | # given strategies, for example, `config.http_authenticatable = [:database]` will
60 | # enable it only for database authentication. The supported strategies are:
61 | # :database = Support basic authentication with authentication key + password
62 | # config.http_authenticatable = false
63 |
64 | # If http headers should be returned for AJAX requests. True by default.
65 | # config.http_authenticatable_on_xhr = true
66 |
67 | # The realm used in Http Basic Authentication. 'Application' by default.
68 | # config.http_authentication_realm = 'Application'
69 |
70 | # It will change confirmation, password recovery and other workflows
71 | # to behave the same regardless if the e-mail provided was right or wrong.
72 | # Does not affect registerable.
73 | # config.paranoid = true
74 |
75 | # By default Devise will store the user in session. You can skip storage for
76 | # particular strategies by setting this option.
77 | # Notice that if you are skipping storage for all authentication paths, you
78 | # may want to disable generating routes to Devise's sessions controller by
79 | # passing skip: :sessions to `devise_for` in your config/routes.rb
80 | config.skip_session_storage = [:http_auth]
81 |
82 | # By default, Devise cleans up the CSRF token on authentication to
83 | # avoid CSRF token fixation attacks. This means that, when using AJAX
84 | # requests for sign in and sign up, you need to get a new CSRF token
85 | # from the server. You can disable this option at your own risk.
86 | # config.clean_up_csrf_token_on_authentication = true
87 |
88 | # ==> Configuration for :database_authenticatable
89 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If
90 | # using other encryptors, it sets how many times you want the password re-encrypted.
91 | #
92 | # Limiting the stretches to just one in testing will increase the performance of
93 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
94 | # a value less than 10 in other environments. Note that, for bcrypt (the default
95 | # encryptor), the cost increases exponentially with the number of stretches (e.g.
96 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
97 | config.stretches = Rails.env.test? ? 1 : 10
98 |
99 | # Setup a pepper to generate the encrypted password.
100 | # config.pepper = '2ca3a278b8fe99e1a0a8aa3157f92cd2a7a6896bfd51e2626face439974a30593278269f7f96e7a90a7b17b90bd1f800fd8b4b4fe3b94ced215d7626ca6cacc3'
101 |
102 | # ==> Configuration for :confirmable
103 | # A period that the user is allowed to access the website even without
104 | # confirming their account. For instance, if set to 2.days, the user will be
105 | # able to access the website for two days without confirming their account,
106 | # access will be blocked just in the third day. Default is 0.days, meaning
107 | # the user cannot access the website without confirming their account.
108 | # config.allow_unconfirmed_access_for = 2.days
109 |
110 | # A period that the user is allowed to confirm their account before their
111 | # token becomes invalid. For example, if set to 3.days, the user can confirm
112 | # their account within 3 days after the mail was sent, but on the fourth day
113 | # their account can't be confirmed with the token any more.
114 | # Default is nil, meaning there is no restriction on how long a user can take
115 | # before confirming their account.
116 | # config.confirm_within = 3.days
117 |
118 | # If true, requires any email changes to be confirmed (exactly the same way as
119 | # initial account confirmation) to be applied. Requires additional unconfirmed_email
120 | # db field (see migrations). Until confirmed, new email is stored in
121 | # unconfirmed_email column, and copied to email column on successful confirmation.
122 | config.reconfirmable = true
123 |
124 | # Defines which key will be used when confirming an account
125 | # config.confirmation_keys = [ :email ]
126 |
127 | # ==> Configuration for :rememberable
128 | # The time the user will be remembered without asking for credentials again.
129 | # config.remember_for = 2.weeks
130 |
131 | # If true, extends the user's remember period when remembered via cookie.
132 | # config.extend_remember_period = false
133 |
134 | # Options to be passed to the created cookie. For instance, you can set
135 | # secure: true in order to force SSL only cookies.
136 | # config.rememberable_options = {}
137 |
138 | # ==> Configuration for :validatable
139 | # Range for password length.
140 | config.password_length = 8..128
141 |
142 | # Email regex used to validate email formats. It simply asserts that
143 | # one (and only one) @ exists in the given string. This is mainly
144 | # to give user feedback and not to assert the e-mail validity.
145 | # config.email_regexp = /\A[^@]+@[^@]+\z/
146 |
147 | # ==> Configuration for :timeoutable
148 | # The time you want to timeout the user session without activity. After this
149 | # time the user will be asked for credentials again. Default is 30 minutes.
150 | # config.timeout_in = 30.minutes
151 |
152 | # If true, expires auth token on session timeout.
153 | # config.expire_auth_token_on_timeout = false
154 |
155 | # ==> Configuration for :lockable
156 | # Defines which strategy will be used to lock an account.
157 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
158 | # :none = No lock strategy. You should handle locking by yourself.
159 | # config.lock_strategy = :failed_attempts
160 |
161 | # Defines which key will be used when locking and unlocking an account
162 | # config.unlock_keys = [ :email ]
163 |
164 | # Defines which strategy will be used to unlock an account.
165 | # :email = Sends an unlock link to the user email
166 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
167 | # :both = Enables both strategies
168 | # :none = No unlock strategy. You should handle unlocking by yourself.
169 | # config.unlock_strategy = :both
170 |
171 | # Number of authentication tries before locking an account if lock_strategy
172 | # is failed attempts.
173 | # config.maximum_attempts = 20
174 |
175 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
176 | # config.unlock_in = 1.hour
177 |
178 | # Warn on the last attempt before the account is locked.
179 | # config.last_attempt_warning = false
180 |
181 | # ==> Configuration for :recoverable
182 | #
183 | # Defines which key will be used when recovering the password for an account
184 | # config.reset_password_keys = [ :email ]
185 |
186 | # Time interval you can reset your password with a reset password key.
187 | # Don't put a too small interval or your users won't have the time to
188 | # change their passwords.
189 | config.reset_password_within = 6.hours
190 |
191 | # ==> Configuration for :encryptable
192 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use
193 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
194 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
195 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
196 | # REST_AUTH_SITE_KEY to pepper).
197 | #
198 | # Require the `devise-encryptable` gem when using anything other than bcrypt
199 | # config.encryptor = :sha512
200 |
201 | # ==> Scopes configuration
202 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
203 | # "users/sessions/new". It's turned off by default because it's slower if you
204 | # are using only default views.
205 | # config.scoped_views = false
206 |
207 | # Configure the default scope given to Warden. By default it's the first
208 | # devise role declared in your routes (usually :user).
209 | # config.default_scope = :user
210 |
211 | # Set this configuration to false if you want /users/sign_out to sign out
212 | # only the current scope. By default, Devise signs out all scopes.
213 | # config.sign_out_all_scopes = true
214 |
215 | # ==> Navigation configuration
216 | # Lists the formats that should be treated as navigational. Formats like
217 | # :html, should redirect to the sign in page when the user does not have
218 | # access, but formats like :xml or :json, should return 401.
219 | #
220 | # If you have any extra navigational formats, like :iphone or :mobile, you
221 | # should add them to the navigational formats lists.
222 | #
223 | # The "*/*" below is required to match Internet Explorer requests.
224 | # config.navigational_formats = ['*/*', :html]
225 |
226 | # The default HTTP method used to sign out a resource. Default is :delete.
227 | config.sign_out_via = :delete
228 |
229 | # ==> OmniAuth
230 | # Add a new OmniAuth provider. Check the wiki for more information on setting
231 | # up on your models and hooks.
232 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
233 |
234 | # ==> Warden configuration
235 | # If you want to use other strategies, that are not supported by Devise, or
236 | # change the failure app, you can configure them inside the config.warden block.
237 | #
238 | # config.warden do |manager|
239 | # manager.intercept_401 = false
240 | # manager.default_strategies(scope: :user).unshift :some_external_strategy
241 | # end
242 |
243 | # ==> Mountable engine configurations
244 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine
245 | # is mountable, there are some extra configurations to be taken into account.
246 | # The following options are available, assuming the engine is mounted as:
247 | #
248 | # mount MyEngine, at: '/my_engine'
249 | #
250 | # The router that invoked `devise_for`, in the example above, would be:
251 | # config.router_name = :my_engine
252 | #
253 | # When using omniauth, Devise cannot automatically set Omniauth path,
254 | # so you need to do it manually. For the users scope, it would be:
255 | # config.omniauth_path_prefix = '/my_engine/users/auth'
256 | end
257 |
--------------------------------------------------------------------------------