Rails 4 Json data-type and forms to use.
For caching based on ActiveRecord array i.e. single key for all restaurants
Your helper function which is available throughout the app
def restaurant_promotion_key # to use this check file pages/home.html.erb
count = Restaurant.order_by_fee_plans.count
max_updated_at = Restaurant.order_by_fee_plans.maximum(:updated_at).try(:utc).try(:to_s, :number)
def all_restaurant_key # to use this check file shared/_header_banner.html.erb
count = Restaurant.count
max_updated_at = Restaurant.maximum(:updated_at).try(:utc).try(:to_s, :number)
Using this in your view
<% cache(all_restaurant_key) do %>
<!– Your UI logic goes here–>
<% end %>
For caching for single row in ActiveRecord
<% cache(restaurant) do %>
<!–Your UI code on ActiveRecord: restaurant goes here–>
<% end %>
The key will be made by by rails and maintained automatically by Rails
Rails doesn’t serve static assets in production mode by default. If you want to disable this and serve the static assets, update your config/environments/production.rb file with this:
config.serve_static_assets = true
The reasoning behind Rails’ default configuration is that it assumes you’ll be running behind a standard web server in production mode (Apache, Nginx, etc.) which will then proxy the requests to your Rails app. Since the assets are precompiled, Apache/Nginx/etc. can directly serve them without needing to talk to your Rails processes.
Precompile your assets on local server using the below cmd from app
$>rake assets:precompile RAILS_ENV=production
Then edit your config/environments/roductions.rb and set the below flag to true, so that rails server sends assets from server
config.serve_static_assets = false
then start your local server as production
$>rails server -e production
Post your usage u can remove the precompiled assets from the local env using
Here is the link to discussion on Stackoverflow about the datatypes that Rails supports.
I found out rails also supports
data types. i want to know to use them. plz help me to complete this post here.
Plz, go to this url….
I was in the same situation:
If you are like me,and Ryan Bates, you like doing the important things yourself. If there are errors, they are your errors.
Chances are you will want to create your Rails authentication from scratch yourself. Ryan of Railscasts has an excellent screencast about this.
I switched from Devise to the custom authentication using this screencast. It was a breeze.
So now comes the customisation. One of these is the all-important Rails authentication redirect back to the funnel a user came from after they are done signing in, or up.
This can actually be achieved very easily:
Say I have a CharitiesController, that I want to close to unauthenticated users. In line with Devise, I would do this to force them to authenticate:
class CharitiesController > ApplicationController
before_filter :authenticate_user!, except: [:show, :index]
Set a return point
In my ApplicationController, given i have set the user sign in route to user_login, I can define a return point: