Ruby on Rails Monday, September 29, 2014

Got the solution and sovled, that was the issue with JS

On Sunday, 28 September 2014 19:34:43 UTC+4, amruby wrote:

HI,
I am trying to add the offline access with my rails 4 application with the reference of railscast (http://railscasts.com/episodes/248-offline-apps-part-2), but the problem with rails 4 is its not caching the JS & CSS files. its seems like

CACHE MANIFEST
b84e022ceae173fbc8d0c0dff68b25e9109869d744f42f1cacebfa87b96865a7
404.html
422.html
500.html

NETWORK:
*
is there any way to do the caching js & css with rails 4

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f3803ec8-37e5-465d-99fb-2d983b5c14a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Glad to see it working. Happy Coding :) 

On Mon, Sep 29, 2014 at 12:51 PM, Paolo Wang <paulwangzy@gmail.com> wrote:
I finally got it working in ActiveAdmin without a custom form. I'll post how I did it for references if somebody need.
First I set my custom attributes in the LineItem model:

class LineItem < ActiveRecord::Base
attr_accessor :source
attr_accessor :target

(it doesn't work adding :source and :target to the ActiveAdmin file under permit_params, I get an error that there are no column with :source/:target if not added to the model with attr_accessor)

ActiveAdmin.register Order do

  permit_params :id, :title,
                line_items_attributes: [:id, :order_id, :language_pair_id, :source, :target]

  form do |f|
    f.inputs do
      f.input :title
      f.has_many :line_items, :allow_destroy => true do |cf|
        cf.input :source, :collection => Language.pluck(:lang)
        cf.input :target, :collection => Language.pluck(:lang)
      end
    end
    f.actions
  end

  controller do
    def create
      @order = Order.create(:title => params[:order][:title])
      params[:order][:line_items_attributes].each do |x, y|
        source = Language.find_by_lang(y[:source])
        target = Language.find_by_lang(y[:target])
        pair = LanguagePair.find_by(:source_id => source.id, :target_id => target.id)
        @order.line_items.create(:language_pair => pair)
      end
      create!
    end
  end
end

it work flawlessly.

Thank you all for the help.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8ee16610-4b5b-42a6-9327-7098a42e69df%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj-KNFSgtmwJ0Aw3NEt-8_tVwBcN5ps0NMei%2BeHSZ3WJOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Recently i have posted this issue, so then i tried another way to cache the javascript and css, things like

This is routes.rb

offline = Rack::Offline.configure  do     cache ActionController::Base.helpers.asset_path("application.css")  cache ActionController::Base.helpers.asset_path("application.js")  cache ActionController::Base.helpers.asset_path("jquery.offline.js")  cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.js")  cache ActionController::Base.helpers.asset_path("json.js")    network "/"  end  get "/application.manifest" => offline

This is the application.html.erb

<!DOCTYPE html>  <html manifest="/application.manifest">  <head>  <title>OfflineTest</title>  <%= stylesheet_link_tag    'application', media: 'all' %>  <%= javascript_include_tag 'application' %>  <%= csrf_meta_tags %>  </head>  <body>    <%= yield %>    </body>  </html>

This is index.html.erb

Listing    <%= form_for Item.new do |f| %>  <p>  <%= f.text_field :name %>  <%= f.submit "Add" %>  </p>  <% end %>    <script type="text/html" id="item_template">  <li>${name}</li>  </script>  <ol id="items">  <li><em>Loading items...</em></li>  </ol>

This is application.js

//= require jquery  //= require jquery_ujs  //= require jquery.tmpl.min  //= require jquery.offline  //= require json  //= require_tree .    $(document).ready(function(){  if ($.support.localStorage) {  $(window.applicationCache).bind("error", function() {    console.log("There was an error when loading the cache manifest.");  });  if (!localStorage["pendingItems"]) {    localStorage["pendingItems"] = JSON.stringify([]);  }  $.retrieveJSON("/items.json", function(data) {    var pendingItems = $.parseJSON(localStorage["pendingItems"]);    $("#items").html($("#item_template").tmpl(data.concat(pendingItems)));  });    } else {  alert("Try a different browser.");  }  });

and added the gem

gem "rack-offline"

after this when i go for the application.manifest , it seems like

CACHE MANIFEST  # 1ad140903542ef1549ddf41cb57e9105786a8b344d7fab9278323e9402e61d14  /assets/application.css  /assets/application.js  /assets/jquery.offline.js  /assets/jquery.tmpl.min.js  /assets/json.js    NETWORK:   /

So the problem coming here like, when i stop the server and check, its not loading the JS and CSS files, that means not loading the data in view, but its working with online, actually i have tried the same way in rails 4.0.2 and ruby 2.0.0 that worked. but when i comes to rails 4.1.6 and ruby 2.1.2 its not working with the offline mode. is there any issues with my configuration and all these?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4812a05e-b212-4adb-a7b7-ac4f79ab8f55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.