| Upload static webpage to wordpress Posted: 05 Jan 2017 07:40 AM PST I am building a reservations app and I would like an advice on how to design the models. I have Reservation and Table model currently designed like this: class Table < ApplicationRecord belongs_to :restaurant has_many :reservations end class Reservation < ApplicationRecord belongs_to :table belongs_to :restaurant end However, often the restaurant needs to make 1 reservation for several tables - for a group of 10 people 2 tables are joined together and both of them should not be available at the given time. In this case, I have 2 options: - Create 2 identical reservations for the 2 tables(easy but seems unnecessary as there might be events with 10 tables needed)
- Create a new model ReservationTable and changing the models to:
class Table < ApplicationRecord belongs_to :restaurant belongs_to :reservation_table end class Reservation < ApplicationRecord has_one :reservation_table has_many :tables, through: :reservation_table belongs_to :restaurant end class ReservationTable < ApplicationRecord belongs_to :reservation has_many :tables end Which choice do you think is better in the long-run(and if the second, is the design accurate?)? Thank you very much for any suggestions! |
| Save dynamic fields in Rails Posted: 05 Jan 2017 07:34 AM PST In my Rails app I Pages, Blocks, BlockContents, Fields, and FieldContents. The associations are: class Page < ActiveRecord::Base has_many :blocks has_many :block_contents, :through => :blocks end class Block < ActiveRecord::Base belongs_to :page has_many :block_contents end class BlockContent < ActiveRecord::Base belongs_to :block has_many :field_contents end class Field < ActiveRecord::Base has_many :field_contents end class FieldContent < ActiveRecord::Base belongs_to :block_content belongs_to :field validates :content, presence: true end Using this I am able to have dynamic fields for Page. However writing to the DB is currently done in the controller like so: def update @page = Page.find(params[:id]) if params[:field_content].present? params[:field_content].each do |block_content| block_content.last.each do |field| field_content_row = FieldContent.where(block_content_id: block_content.first, field_id: field.first).first if field_content_row.present? field_content_row.update(content: field.last) else field_content = FieldContent.new field_content.block_content_id = block_content.first field_content.field_id = field.first field_content.content = field.last field_content.save end end end end if @page.update_attributes(page_params) redirect_to pages_path else render 'edit' end end While this does in work, it's quite dirty and it doesn't show my validations for my FieldContent in the view (the validations do work as they don't save the FieldContent if they are invalid, but it should prevent the whole page from saving and show it in the view). How can I make it so that I can show the validations for FieldContent? |
| Rails - Temporarily update active record object's attribute Posted: 05 Jan 2017 07:40 AM PST Is there a way to transform model attributes temporarily in a different format but preserve the original value when requested again? Here's an example of the model: class User < ActiveRecord::Base has_many :emails, order: "sent_at desc, id desc", dependent: :destroy, inverse_of: :user def sanitized_emails emails.map do |e| e.assign_attributes({body: Sanitize.fragment(e.body)}) e end end end Basically I want to be able to run user.sanitized_emails and have the body sanitized, but when running user.emails immediately after, the sanitized values are saved and require user.emails.reload to reset the values. Is there a way to avoid this so that the data is only transformed for the return value of the sanitized_emails method? Better yet, is there a way to add this method to the emails model? class Email < ActiveRecord::Base # ... def with_sanitized_body update_attribute :body, Sanitize.fragment(body) self end end Something like the above, so that I can run user.emails.map(&:with_sanitized_body), so that the concern is removed from the user model. I still want to be able to run user.emails immediately after and expect body to contain its original value. I feel like this should be simple and that I'm missing something obvious :/ |
| Why does url_for([:new, User]) generate new_users_path (instead of new_user_path)? Posted: 05 Jan 2017 07:29 AM PST I want to use the same partial for many different resource types. In it, I create a link to create the resource. I pass the resource class as parameter: render partial: 'my_partial', resource: User I find it interesting though that when doing this in the partial: url_for [:new, resource] Rails complains: undefined method `new_users_path' So it makes a users from the User class, which means: it makes a string out of it and converts it to plural. To solve the problem, I have to do this: url_for [:new, resource.to_s.underscore] Why is that? What's the reason that Rails pluralises a model's class name in this situation? Is there a more elegant solution for this? |
| Rails create action: Forbidden Attributes Error Posted: 05 Jan 2017 07:36 AM PST I am new to rails and am in the process of entering in information in a form and saving it to a database. I am following a tutorial which may be out of date. I am getting an error on the second line. Am I passing the wrong parameter? def create @student = Student.new(params[:student]) if @student.save redirect_to new_student_path end end |
| adding scripts to spree - creating order Posted: 05 Jan 2017 07:14 AM PST |
| Using Ember.$.ajax() to send data that has relationships Posted: 05 Jan 2017 07:12 AM PST I'm running through a headache. I'm using Ember 2.0 (a bit old, I know...!). Due to the nature of the project (using ruby-on-rails) we have to use Ember,$.ajax() to manage the data instead of Ember-Data. We're trying to send a data object that has a relationship with another data model, but it throw an: Uncaught TypeError: Cannot read property 'options' of undefined Ember (controller): import Ember from 'ember'; export default Ember.Controller.extend({ sendFileData(url, verb, filetype, isSelected) { let controller = this; Ember.run.next(this, () => { Ember.$.ajax({ url: url, type: verb, data: { title: controller.get('model.title'), files: Ember.A([ controller.store.createRecord('file', { selected: isSelected, pdf: (filetype === 'pdf') ? 'pdf' : null, html: (filetype === 'html') ? 'html' : null }) ]) } }).then(() => { controller.set('successMessage', 'Pdf Data sent to backend!'); }, () => { controller.set('successMessage', 'Something is wrong with PDF data!'); }); console.log('end sendFileData()!'); }); }, actions: { exportData() { let controller = this, dataLink = controller.get('model.dataLink'); console.log('Data link: ', dataLink); console.log('Model title: ', controller.get('model.title')); if (controller.get('isPdfChecked')) { console.log('PDF is chosen!'); controller.sendFileData(dataLink, 'POST', 'pdf', controller.get('isPdfChecked')); } if (controller.get('isHtmlChecked')) { console.log('HTML is chosen!'); controller.sendFileData(dataLink, 'POST', 'html', controller.get('isHtmlChecked')); } if (!controller.get('isPdfChecked') && !controller.get('isHtmlChecked')) { console.log('No options chosen!'); } } } }); Model: // document model import DS from 'ember-data'; export default DS.Model.extend({ title: DS.attr('string'), content: DS.attr('string'), created_at: DS.attr('date'), start_at: DS.attr('utc'), end_at: DS.attr('utc'), user: DS.belongsTo('user', { async: true }), versions: DS.hasMany('version', { async: true }), files: DS.hasMany('file', { async: true }), // here's the relationship to file model dataLink: Ember.computed('id', function() { return "/export/data/document/" + (this.get('id')); }) }); // file model import Ember from 'ember'; import DS from 'ember-data'; export default DS.Model.extend({ name: DS.attr('string'), url: DS.attr('string'), created_at: DS.attr('date'), document: DS.belongsTo('document', { async: true }), // here's the relationship to document model filetype: DS.attr('string'), selected: DS.attr('boolean'), pdf: DS.attr('boolean'), html: DS.attr('boolean') }); Don't know what to do anymore :(... And we can't add the addon ember-data-save-relationships or similar, again because of how the project is structured. Many thanks |
| How to declare custom attribute accessor with dynamic argument in Ruby? Posted: 05 Jan 2017 07:07 AM PST I want to declare a custom accessor in a Rails model like this: footnote_attrs :title, :body Then I want to access footnote_attrs in a method inside the model. footnote_attrs need to just return an array containing the args passed to it. In this case, it will be [:title, :body]. What is the best way to implement this? |
| Accessing attr_accessor attributes with variable Posted: 05 Jan 2017 07:10 AM PST below question is about selecting the attributes enabled by "attr_accessor" for an object. Example: class Openhour < ActiveRecord::Base belongs_to :shop attr_accessor :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday end This allows me to week = Openhour.new week.monday = "Open" week.tuesday = "Closed" My question: How can I select the attr_accessors by using a variable from a loop? In below case I would use dayname to select the attr_accessor. @schedules.each do |schedule| %w(monday tuesday wednesday thursday friday saturday sunday).each_with_index do |dayname,dayname_index| week.dayname = schedule.day == dayname_index ? "Open" : "Closed" end end This, however, would result in *** NoMethodError Exception: undefined method `dayname' for #<Model> Thanks in advance! |
| Test Ruby module Posted: 05 Jan 2017 07:41 AM PST I'm very new to Ruby and and RSpec. I would like to create basic Spec file for this module: module DownloadAttemptsHelper def download_attempt_filter_select_options search_types = [ [I18n.t("helpers.download_attempts.search_types_default"), 'default' ], [I18n.t("helpers.download_attempts.search_types_account_id"), 'account_id' ], [I18n.t("helpers.download_attempts.search_types_remote_ip"), 'remote_ip' ], ] options_for_select(search_types) end end Small test describe DownloadAttemptsHelper do it "does something" do expect(1).to be_odd end end I get: `<top (required)>': uninitialized constant DownloadAttemptsHelper (NameError) Do I need to import the directory path and module name? Can you give me some very basic example how I can test this module? |
| how i can pass "var status = true" from my jquery script to the js.erb file or other solutions? Posted: 05 Jan 2017 07:24 AM PST I have a controller action that looks like this: @sports = @articles.sports.paginate(page: params[:sports_page], per_page: 6) @world = @articles.world.paginate(page: params[:world_page], per_page: 6) respond_to do |format| format.html { render 'index_region' } format.js { render :file => "/articles/latest.js.erb" } end And both of these objects are paginated in the view at the same time. And I want to paginate both of these objects through ajax/js.erb $(document).on('turbolinks:load', function () { if($('#sports').size() > 0) { $('.sports-pagination').hide(); $('#load_more_photos_sports').show(); $('#load_more_photos_sports').on('click', function() { var urlsports = $('.sports-pagination>.pagination .next_page a').attr('href'); $.getScript(urlsports); }); } if($('#world').size() > 0) { $('.world-pagination').hide(); $('#load_more_photos_world').show(); $('#load_more_photos_world').on('click', function() { var urlworld = $('.world-pagination>.pagination .next_page a').attr('href'); $.getScript(urlworld); }) } }); but whichever button is clicked, I guess it has to go through the same js.erb file? Is that correct? Or can i somehow tell the controller to respond with different js.erb files depending on which button was clicked? Or, if I can add var status = true and var status = false into the code and pass that into the js.erb file, then I can setup an if statement that only runs the code related to the button that was clicked. |
| Rails validation if association has value Posted: 05 Jan 2017 06:39 AM PST In my Rails app I have Content, Fields, and FieldContents. The associations are: class Content < ActiveRecord::Base has_many :field_contents end class Field < ActiveRecord::Base has_many :field_contents end class FieldContent < ActiveRecord::Base belongs_to :content belongs_to :field end Fields contain columns that describe the field, such as name, required, and validation. What I want to do is validate the FieldContent using the data from its Field. So for example: class FieldContent < ActiveRecord::Base belongs_to :content belongs_to :field # validate the field_content using validation from the field validates :content, presence: true if self.field.required == 1 validates :content, numericality: true if self.field.validation == 'Number' end However I'm currently getting the error: undefined method 'field' for #<Class:0x007f9013063c90> but I'm using RubyMine and the model can see the association fine... It would seem self is the incorrect thing to use here! What should I be using? How can I apply the validation based on its parent values? |
| Fail to download a remote https svg file but embed inside <img> is good Posted: 05 Jan 2017 06:45 AM PST I have a https link, embedded into <img>, everything is good. Such as https://jsfiddle.net/Lbhhtt6n/. However, if you try to download link directly such as directly open it with browser with link https://version.gitlab.com/check.svg?gitlab_info=eyJ2ZXJzaW9uIjoiOC4xNi4wLXByZSJ9 , then 404 error returned. Due to this issue, I cannot check head by httparty response = HTTParty.head('https://version.gitlab.com/check.svg?gitlab_info=eyJ2ZXJzaW9uIjoiOC4xNi4wLXByZSJ9') puts response.success? # always return false What's the magic behind it? Anyone could enlighten me? Thanks. |
| split I18n into sperate files Posted: 05 Jan 2017 06:54 AM PST one of the requirement is to split I18n. I have been looking into the link below in section organization of local files http://guides.rubyonrails.org/i18n.html If i look at the config/locales/en-US.yml in my project i dont see anything for model, view or controller. I see the data about the items of the webpage. en-US.yml looks like this en-US: Healthe: Points: my_points: "Point %{unit}" status: "Points achieved" Am i looking at wrong file? How do i split i18n for model, views and controller that has translation? Thanks |
| Rails: parse weirdly-formatted JSON Posted: 05 Jan 2017 06:27 AM PST My JSON response from an external service looks like this: Parameters: {"{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/lead/2231\"},\"Id\":\"2231\",\"FirstName\":\"Jean\"}"=>nil, "external_id"=>"2231"} How can I parse the Id and FirstName keys in Rails 5? I've tried everything. I know Rails 5 has the .to_unsafe_h method, that's not my problem. It's more the weird nested formatting that has a value of nil after "Jean" above. |
| phone number rails js Posted: 05 Jan 2017 06:28 AM PST Is is possible to do this in rails. I have read about turbolinks. and have tried to adapt it for rails but was unable. document.getElementById('phone').addEventListener('input', function (e) { var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/); e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : ''); }); <input type="text" id="phone" placeholder="(555) 555-5555"/> this code comes from: Mask US phone number string with JavaScript Thank you! |
| Run basic rspec file Posted: 05 Jan 2017 06:38 AM PST I'm new to Ruby and RSpec. I want to create very simple RSpec test: # test_spec.rb require 'spec_helper' describe TestController do puts(Time.now) end But when I run the code this way rspec test_spec.rb I get error: `<top (required)>': uninitialized constant TestController (NameError) Can you give me some idea where I'm wrong? |
| How does SymmetricDS convert Oracle RAW to Postgres BYTEA? Posted: 05 Jan 2017 05:54 AM PST I'm using SymmetricDS to replicate data from an Oracle DB to a Postgres DB, and let it create the schema in the Postgres slave. A column with type RAW in Oracle was converted to BYTEA in Postgres. Values are converted as such RAW: 24E1EB73A5CA0D17E05400144FF9F89C BYTEA: \x24E1EB73A5CA0D17E05400144FF9F89C I.e., somewhere in the process, the value gets prepended with \x. Querying using the prepended string in psql works fine. However, when I try to query it from my Rails application, I only get empty results, both with the RAW string and the prepended BYTEA string. If I try to use the suggested Rails util methods like escape_bytea(), I get a string that looks like this \\x3234453145423733413543413044313745303534303031343446463946383943 Is this the format SymmetricDS should have used to input the data in the Postgres DB? Or is there a way to tweak the query string so I can get the results on the current format? |
| Can't add session variable - ActiveModel::MissingAttributeError Posted: 05 Jan 2017 06:20 AM PST I am not very confident with Rails but have recently started adding custom session variables in order to store some data such as id's. I am trying to set a call id to a recently created value but keep getting an error. Code: callid = Call.createCall(sessionid,tp_cd) session[:callid] = callid This exact same thing works in other actions in the same controller, but here I get: ActiveModel::MissingAttributeError (can't write unknown attribute `callid`) I am simply calling this action with a POST call in order to manipulate some data and set this session variable to be used later. There must be something fundamental that I am missing about how session variables work. Is there anything obvious that could cause this error? |
| Minitest::UnexpectedError: ActiveRecord::RecordNotUnique: Mysql2::Error: Posted: 05 Jan 2017 06:45 AM PST I got a error that Minitest::UnexpectedError: ActiveRecord::RecordNotUnique: \ Mysql2::Error: Duplicate entry '' for key 'index_users_on_email': \ INSERT INTO `users` (`created_at`, `updated_at`, `id`) \ VALUES ('2017-01-05 13:05:14', '2017-01-05 13:05:14', 298486. I wrote in home_controller, class HomeController < ApplicationController before_filter :find_user, only: [:index] def index @id = params[:id] @email = [:email] if @id == @user.id && @email == @user.email render :text => "sucsess" else render :text => "fail" end end def create userData = UserData.new(create_params) user = User.find(params[:id]).to_json # エラー処理 unless userData.save @error_message = [memo.errors.full_messages].compact end end private def find_user @user = User.find(params[:id]) # You should specify this code what are your comparing to. end end Before,I got a error that user variable is nil. So,I debuted user = User.find(params[:id]).to_json and I got a error like above. But in localhost:3000, I got a error that Routing Error undefined method ` ' for HomeController:Class. Therefore,I really cannot understand what is wrong. How can I fix this error? in routes.rb,I wrote Rails.application.routes.draw do devise_for :users root to: "home#index" get 'home/index' namespace :home, default: {format: :json} do resources :index, only: :create end in test_helper.rb ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # Add more helper methods to be used by all tests here... end in home_controller_test.rb require 'test_helper' class HomeControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success end end |
| Getting each i element of a ruby array in a javascript function (escaping and unescaping)? Posted: 05 Jan 2017 05:26 AM PST Say, in ruby I've got an array: ruby_array = [1, 2, 3, 4, 5] In my javascript script, I want to be able to push every element from myruby_array to a javascriptArray: var javascriptArray = []; for (i = 0; i < <%= raw ruby_array.size %>; i++) { alert("The " + i + ". element of my ruby array is: " + <%= raw ruby_array[i] %>); // Problem: I guess, I cannot get the i javascript variable when calling ruby_array[i] // How do I unescape the i? // Now push every ruby_array element into my javascriptArray // Same problem like above javascriptArray[i] = Number(<%= raw ruby_array[i] %>); } The error message I get is: SyntaxError: expected expression, got ')' Note: If I leave the [i] in ruby_array[i] out, the output is fine: The 0. element of my ruby array is: 1,2,3,4,5 ... The 4. element of my ruby array is: 1,2,3,4,5 I've also tried .to_json.html_safe with the same results. So how do I get the i-th element from my ruby array in javascript code? |
| Namespacing within `app` directory Posted: 05 Jan 2017 04:56 AM PST In our app directory, we want some of the sub-directories to contain namespaced classes, and some that contain top-level classes. For example: app/models/user.rb defines ::User app/operations/foo.rb defines ::Operations::Foo app/operations/user/foo.rb defines ::Operations::User::Foo Our application.rb contains the following configuration: config.paths = Rails::Paths::Root.new(Rails.root) config.paths.add 'app/models', eager_load: true config.paths.add 'app', eager_load: true This works fine in most cases, but sometimes in development mode and with Rails' autoreloading turned on, this leads to the wrong classes being loaded. For instance ::User is mistaken for Operations::User and vice-versa. Is there a way to configure this behavior so that it works without any errors? If not, the only workaround I can think of is to create a second directory for "namespaced" classes, along the lines of app and app_namespaced. Or else app/namespaced, since app-level code should reside within app. But these seem like ugly workarounds to me. |
| Ruby ajax js view returns encoded html instead of valid html Posted: 05 Jan 2017 05:02 AM PST I've got a javascript view (add_to_garden.js.erb) that responds to an ajax action and tries to render a flash message telling the user about the updated info. This works: // Flash message to user <% flash.each do |key, message| %> $("#flash").html("<%= j(render( partial: "shared/flash_message", locals: {key: key, message: message } )) %>"); <% end %> Of course as it's written above, the html for each flash message will replace the previous one so only the last message will be shown to the user. This does render all the messages... // Flash message to user <% flash[:error] = "AAAAHHHHHH... an error" %> <% flash[:info] = "Just so you know, that was an error." %> <% flash.each do |key, message| %> <% (@alerts ||= '') << render( partial: "shared/flash_message", locals: {key: key, message: message } ) %> <% end %> $("#flash").html("<%= j(@alerts) %>"); flashMessageSetTimeout(); ...but the messages in @alerts are htmlencoded by the time they get to the browser:  How to fix? |
| Reading YAML from ruby is printing incorrect values Posted: 05 Jan 2017 05:41 AM PST I have a YAML file with the following structure: mytext: mykey: "\x9A\xA6@\e8ddw\xB6&*\xFFr\x81\\\xC8@\xCC\x1E^\xD6\x13^\xD2\x91\x17\xEA\xB0\x001\xDD\xC1" myvalue: "8\xD8I\x00=\x9E\xF2I\x99tUK\xFD\x16\xA3Y" I use the below ruby code to read data from this YAML file: yamlfilen = YAML::load_file('yamlfile.yml') #Load mykey = yamlfilen['mytext']['mykey'] myiv = yamlfilen['mytext']['myvalue'] p mykey p myiv When I see the value printed in the console i see this: "\\x9A\\xA6@\\e8ddw\\xB6&*\\xFFr\\x81\\\\\\xC8@\\xCC\\x1E^\\xD6\\x13^\\xD2\\x91\\x17\\xEA\\xB0\\x001\\xDD\\xC1" "8\\xD8I\\x00=\\x9E\\xF2I\\x99tUK\\xFD\\x16\\xA3Y" Any idea why this is happening? |
| Writing a scope for multiple associations - Rails 4 Posted: 05 Jan 2017 05:03 AM PST I am having challenges writing a scope to display: - all cards belonging to events that have payments that belong to a specific user
- i am currently able to display, all events that have payments that belong to a specific user using the scope
scope :booked_events, -> (user) { joins(payments: :user).where(users: { id: user.id }) } in the event.rb file - some events have a card and some don't
could one kindly advise me how i display all events with a card that have payments that belong to a specific user event.rb has_many :payments has_one :card scope :booked_events_with_cards, -> (user) { joins(payments: :user).where(users: { id: user.id }) } card.rb belongs_to :event payment.rb belongs_to :event belongs_to :user user.rb has_many :payments i tried the below in the card.rb file but i am unsure belongs_to :event has_many :payments, through: :event scope :cards_belonging_to_booked_events, -> (user) { joins(payments: :event).where(users: { id: user.id }) } but got the below error: 2.3.0 :012 > cards.cards_belonging_to_booked_events(user) Card Load (0.6ms) SELECT "cards".* FROM "cards" INNER JOIN "events" ON "events"."id" = "cards"."event_id" INNER JOIN "payments" ON "payments"."event_id" = "events"."id" INNER JOIN "events" "events_payments" ON "events_payments"."id" = "payments"."event_id" WHERE "users"."id" = 4 SQLite3::SQLException: no such column: users.id: SELECT "cards".* FROM "cards" INNER JOIN "events" ON "events"."id" = "cards"."event_id" INNER JOIN "payments" ON "payments"."event_id" = "events"."id" INNER JOIN "events" "events_payments" ON "events_payments"."id" = "payments"."event_id" WHERE "users"."id" = 4 ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: users.id: SELECT "cards".* FROM "cards" INNER JOIN "events" ON "events"."id" = "cards"."event_id" INNER JOIN "payments" ON "payments"."event_id" = "events"."id" INNER JOIN "events" "events_payments" ON "events_payments"."id" = "payments"."event_id" WHERE "users"."id" = 4 or, am i to write the scope in event.rb file if i want to display all cards with events that have payments that have been made by a user? |
| how to create a user interface that a user can signup and login using reactjs and rails backend Posted: 05 Jan 2017 04:58 AM PST I'm very new to react but i'm experience with rails, i want know how to create user signup and login using react, can please any suggests what are the steps needed create registration process using react and rails. |
| Rails / Postgres: Get percentage of availability Posted: 05 Jan 2017 06:28 AM PST I am using a Postgres database (CalendarEntry) in which I store entries with start_date and end_date values. Now I want to check if I am available for a certain timespan (check_start, check_end): count_entries = CalendarEntry.where('start_date <= ?', check_end).where('end_date >= ?', check_start).count i_am_available = count_entries == 0 I want to change this behavior to get the percentage of availability. How could I count the available days instead of the entries themselves? |
| Why is my Rails App faster on Heroku than on my Localhost Posted: 05 Jan 2017 04:25 AM PST When I was developing my Rails app I noticed that it got extremely slow as soon as I included some background File creation via Amazon S3. When I uploaded my site to Heroku the load time dropped a lot. On my local server a page load takes about ~12s, on Heroku just ~1s. Why does my app run that much slower on my local computer? Does the Heroku server have a faster connection to the Amazon S3 servers? |
| Create a JS component from remote call Posted: 05 Jan 2017 03:31 AM PST In my Rails5 app I have the JS component below. class IdentityConfirmation constructor: (item) -> ... @setEvents() setEvents: -> ... I create the components when Turbolinks loads as such $(document).on 'turbolinks:load', -> $.map $("[data-behavior~='identity-confirmation']"), (item, i) -> new IdentityConfirmation(item) And everything works just fine. Now I need to create a component from within a js.erb file. My js.erb file looks like $("#mydiv").html("<%= escape_javascript(render partial: 'mypartial' %>"); $.map($("[data-behavior~='identity-confirmation']"), function(item, i) { return new IdentityConfirmation(item); }); And mypartial contains a div with data behavior equal to identity-confirmation. However, the component is not created. Am I missing anything here? Thanks |
| Can we use two different types of AWS EC2 instances with elastic beanstalk loadbalancer Posted: 05 Jan 2017 03:10 AM PST I'm using elastic beanstalk to host my rails application, I've configured load balancer and I know how to set maximum and minimum numbers of instances of same type(for example 2 instances of T2.micro or 2 instances of T2.medium). My question is can I use two different types of instance in elastic beanstalk load balancer. e.g. one t2.Micro and one T2.Medium in same environment. |
No comments:
Post a Comment