0

I just deployed my site from my local webrick server to a real server,

http://92.51.243.6/

I was delighted I managed to deploy it by myself, but that quickly disappeared on realising most of my links don't work. (I know about the Facebook issue, it's really the links I'm concerned about now) - About Us, FAQ, Contact Us, and on the 'Sign Up' page where the link 'Terms and Conditions' gives the error, 'I'm sorry, but something went wrong'

I made my links with the code:

 <div id = "menu">
      <ul id = "home_page_links">
        <li><%= link_to "Home",about_us_path, :remote => true %></li>
        <li><%= link_to "About Us",about_us_path, :remote => true  %></li>
        <li><%= link_to "FAQ", faq_path, :remote => true  %></li>
        <li><%= link_to "Contact Us", contact_us_path, :remote => true  %></li>
      </ul>
    </div>

All the links work fine in local mode, on WEBrick. In my production log I'm getting a lot of messages, such as:

Started GET "/contact_us" for 77.24.238.174 at Thu May 30 00:11:08 +0100 2013
Processing by StaticPagesController#contact_us as */*
  Rendered static_pages/contact_us.html.erb within layouts/application (0.0ms)
Completed 500 Internal Server Error in 4ms

ActionView::Template::Error (ie.css isn't precompiled):
    12:   <%= javascript_include_tag "application" %>
    13:   <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    14:   <!--[if lt IE 9]>
    15:     <%= stylesheet_link_tag 'ie', :media => 'all' %>
    16:     <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    17:   <![endif]-->
    18: </head>
  app/views/layouts/application.html.erb:15:in `_app_views_layouts_application_html_erb__922519344_37417300'

And here is my routes.rb file:

QuestionnaireSite::Application.routes.draw do

  get "about_us", :to => "static_pages#about_us"
  get "contact_us", :to => "static_pages#contact_us"
  get "faq", :to => "static_pages#faq"
  get "competition_terms", :to => "static_pages#competition_terms"
  get "t_and_c", :to => "static_pages#terms_and_conditions"
  # get "user", :to => @user(current_user)
  get "render_index_review", :to => "reviews#render_index"

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

  devise_scope :user do
    delete "sign_out", :to => "devise/sessions#destroy"
    get "login", :to => "devise/sessions#new"
  end

  devise_for :admins, :path => "admin", :controllers => { :sessions => "admin/sessions" }

  get "home/index"
  get "home/map", :as  => :map
  post "home/update_address", :as  => :update_address
  match "canvas" => "canvas#index"

  match "/contacts/:importer/callback" => "email_invites#contacts_callback", :as => :contacts_callback
  match "/contacts/failure" => "email_invites#contacts_callback_failure", :as => :contacts_callback_failure
  mount Resque::Server, :at => "/resque"

  get "find" => 'search#index', :as => :find

  resources :search do
    collection do
      match :change_range
    end
  end

  resources :reviews do
    member do
      get :repost, :reject
    end
  end
  resources :users do
    member do
      get :following_followers, :address_toggle
    end
  end
  resources :friend_relations, :only => [:create, :destroy]
  resources :email_invites do
    collection do
      get :confirm
      post :invitation_form
      post :outlook_import
    end
  end

  root :to => "home#index"

  namespace :admin do
    resource :profile, :only => [:edit, :update]

    resources :users
    resources :categories
    resources :reviews

    root :to => "users#index"
  end

And my scripts.js file, which does ajax stuff:

//I want to load content into the '.page-content' class, with ajax

var ajax_loaded = (function(response) {        

  $(".page-content")

  .html($(response).filter(".page-content"));       

  $(".page-content .ajax").on("click",ajax_load); 



   });


//the function below is called by links that are described 
//with the class 'ajax', or are in the div 'menu' 

var history = [];                 

// var current_url_method;               

var ajax_load = (function(e) {  


  //console.log('load ajax on clicks. This always works.');         
  e.preventDefault();               


  history.push(this);               
  var url =$(this).attr("href");          
  var method = $(this).attr("data-method");   

  // if (current_url_method != url + method) {   
  //   console.log('You got to the url + method part. But sometimes I dont get this far.'); 
  //   current_url_method = url + method;      

  $.ajax({                  
    url: url,               
    type: method,  
    // async: false,                       
    success: ajax_loaded

    // $('html, body').animate({ scrollTop: 0 }, 0);       
  });
   // }

 });


//monitor for clicks from menu div, or with
//the ajax class, or the 'submit button'.
//why the trigger?

$(document).on("ready", function(){
$("#menu a").on("click",ajax_load);
$(".ajax").on("click",ajax_load);
$("#menu a.main").trigger("click");


});

Any help would be appreciated, thanks.

CHarris
  • 2,693
  • 8
  • 45
  • 71
  • 1
    Nothing in the `production.log` file, or any http log files? – lurker May 29 '13 at 23:02
  • I would appreciate it if you provide us with more information on how you made your links. – Rapture May 29 '13 at 23:10
  • Hi, I didn't know about production.log until now (new to deployment). What does production.log do, exactly? I see in Terminal it changes as I click around my links. I edited my question above with one of the snippets of code from production.log. How can I fix the internal server error? How can I pre-compile ie.css? Thanks. – CHarris May 29 '13 at 23:14
  • possible duplicate of [blueprint/screen.css isn't precompiled](http://stackoverflow.com/questions/7443536/blueprint-screen-css-isnt-precompiled) – jdl May 29 '13 at 23:21
  • Have you precompiled the assests? Looks like you did not. Run rake assets:precompile on server. – rmagnum2002 May 29 '13 at 23:22
  • excuse my ignorance, but do you mean my local server, or the live server on which the app is hosted? – CHarris May 29 '13 at 23:28
  • Server where you deployed – rmagnum2002 May 29 '13 at 23:30
  • Tried that, no error messages but links still don't work. Thanks anyway. – CHarris May 29 '13 at 23:46
  • Show your routes file, looks like they are calling an ajax request – rmagnum2002 May 29 '13 at 23:48
  • Yes, I do use Ajax, although I don't remember any mention of it in my routes file. I'll add my routes file to my question... – CHarris May 29 '13 at 23:52
  • Ad remote: true to links and check the js.erb files for each action you call with these links and post at least one of them in your question – rmagnum2002 May 29 '13 at 23:59
  • you should have a file about_us.js.erb at app/views/static_pages – rmagnum2002 May 30 '13 at 00:01
  • all my views/static_pages are html.erb files. No js.erbs at all. Ajax is done in a scripts.js file. What should my about_us.js.erb consist of? I added remote: true to links, as per question. – CHarris May 30 '13 at 00:18
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30935/discussion-between-rmagnum2002-and-christophe-harris) – rmagnum2002 May 30 '13 at 19:38

3 Answers3

1

ok, I'll explain you step by step how to do an ajax request in rails, at least this is my way of doing it and I am not forcing you to do the same.

1. the link and path

<%= link_to "FAQ", faq_path, :remote => true  %>

setting remote: true to links means the request will be treated as ajax.

the path faq_path means you have it in routes.rb defined (as in your case: get "faq", :to => "static_pages#faq")

2. the controller and action

having your route as get "faq", :to => "static_pages#faq" means that you have a controller called static_pages and an action inside called faq

def faq
  may be some code here but not necessary for static pages
end

3. the views and js.erb

as for now you probably have a faq.html.erb in app/views/static_pages/ and this page will work for html requests, but as we do this as ajax it will look for faq.js.erb and this is where you do the javascript things.

First I would move your faq.html.erb content into a partial _faq_content.html.erb and in faq.html.erb I will only render it as partial <%= render 'faq_content' %>, because we will use the same partial in case there will be a html request(for users who has js disabled in browsers)

now I'll just admit that when clicking on faq link you want to replace the content inside of the page-content div with the content of your faq page. To do so, in your faq.js.erb(create one if you don't have it) you will write:

$('.page-content').html('<%= j render('faq_content') %>');

you can add more js code here if you want and need it, like for exemple to set the style for the links in the menu with the underline or you can do whatever with any element present on that page.

after clicking on faq link content of the <div class="page-content"></div> will be replced with the content of the faq partial content.

I advise you to remove(comment) your js code when you try my method, by the way, Chrome shows errors when clicking on links:

GET http://92.51.243.6/about_us 500 (Internal Server Error) application-
GET http://92.51.243.6/faq 500 (Internal Server Error) application-
GET http://92.51.243.6/contact_us 500 (Internal Server Error) 

so you better remove your js while trying with my tutorial :) just to be sure there will be no conflicts. If you do it all right you should get an ajax render for your static pages. Let me know if you have issues with this. Good luck.

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86
  • Cheers rmagnum, thanks for your very kind help. will look into it shortly. It's certainly different to the ajax way I was thought! If it works though, it's much cleaner and shorter. Might be some problem with 'Submit' buttons, but I'll worry about that when I come to it. I've marked it up 1 and if it works I'll accept your answer. – CHarris May 30 '13 at 08:32
  • 1
    nothing hard with submit buttons, you'll add remote: true to the form and the action that you do in that form will work with ajax just as for the links, for exemple if you do a create user form, <%= form_for @user, remote: true do |f| %> <%= f.email_field :email, placeholder: "Your email" %> <% end %> with this the create action in users controller will respond with js, means that you'll need to have app/views/users/create.js.erb and in it you'll add the js needed. But as you said, you'll worry about it when you'll get to it. – rmagnum2002 May 30 '13 at 10:10
1

Are you deploying your app on production environment?

The error is: ActionView::Template::Error (ie.css isn't precompiled):

This means you need to precompile all your assets. Please run this command and restart your server.

bundle install
bundle exec rake assets:clean
bundle exec rake assets:precompile

for more derails please follow these basic steps as stated in rails deploy guide. http://guides.rubyonrails.org/asset_pipeline.html#in-production

Muhammad Sannan Khalid
  • 3,127
  • 1
  • 22
  • 36
  • thanks for the tip, but didn;t work as I would have liked. Someone said to put *= require_tree in application.css.scss and redeploy, so I'll give that a go. – CHarris May 30 '13 at 12:53
  • *= require_tree will add every css file. I thought that you had written that in appliation.css.scss file. – Muhammad Sannan Khalid May 30 '13 at 12:56
  • I inherited this rails project from someone else. And I'm certainly no expert on rails.But in my application.css.scss file I see *= require for every single scss file in the same folder, except ie.css.scss. Could that be the problem? I mean, just add *= require ie and redeploy? – CHarris May 30 '13 at 13:02
  • ya u can out.. that's the problem – Muhammad Sannan Khalid May 30 '13 at 14:30
0

Are you deploying your app on production environment?

The error is:

ActionView::Template::Error (ie.css isn't precompiled):

This means you need to precompile all your assets. Please run this command and restart your server.

bundle exec rake assets:precompile
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Fatima
  • 1
  • 1