Monday, June 6, 2016

Rename foreign keys automatically in activerecord | Fixed issues

Rename foreign keys automatically in activerecord | Fixed issues


Rename foreign keys automatically in activerecord

Posted: 06 Jun 2016 06:58 AM PDT

I'm doing a rails migration to rename a table and I'd like to rename its foreign keys automatically. E.g. a User has many posts, and I'm renaming User to Person

def change    rename_table :users, :persons  end  

I'd like to create automatically migrations like

def change    rename_column, :posts, :user_id, :person_id  end  

I've thought to get the model form the migration and look at its has_many models, e.g. as described in this answer. Is there a simpler way?

Can Rails be configured to show model attributes in a particular order?

Posted: 06 Jun 2016 06:53 AM PDT

As per this DBA question, it is not possible to specify the order of database columns in PostgreSQL except by creating the columns in the right order in the first place.

However, I don't care about the column order in PostgreSQL itself, as the only time I ever look at the columns is in Rails. Is it possible to configure my models in Rails so that they will display their attributes in an order that I prefer when I inspect them with awesome_print or when printing Model.attribute_names?

Where are the initialize methods for classes in Rails?

Posted: 06 Jun 2016 06:50 AM PDT

Where is the initialize method for classes created in in Rails?

For example, I can create a new class with the following code.

rails g model User  rake db:migrate  

And now I have a /models/user.rb with a User class.

class User < ActiveRecord::Base  end  

But from studying Ruby, I though all classes need to be initialized with an initialize method.

class User      def initialize()      end  end  

But I never see this in Rails. How does Rails get around doing this?

(Currently using Rails 4.)

Tell Mongoid to use another field (other than _type) to handle inheritance

Posted: 06 Jun 2016 06:27 AM PDT

Mongoid automatically creates a _type field to store classes names in order to handle inheritance, as seen in the the docs.

Problem is that we're using a Parse server and reading from the same MongoDB and it just doesn't accept a record with a _type field, is there a way to tell Mongoid to use a custom field instead of _type to handle inheritance?

Sorta duplicate of Mongoid: how use a custom field instad of _type for inheritance really.

Get database size in redis-rails

Posted: 06 Jun 2016 06:23 AM PDT

On the Redis-CLI you can get the size of the database like this:

redis-cli  127.0.0.1:6119> dbsize  (integer) 123  

How can I do the same in redis-rails? And is it even possible?

Nesting in Rails

Posted: 06 Jun 2016 06:19 AM PDT

I am writing an app which has a Restaurant, Menu, Category, and Meal models. How to implement these without nesting more than 2 levels deep?

class Restaurant < ActiveRecord::Base    has_many :menus    has_many :categories, through: :menus    has_many :meals, through: :categories  end    class Menu < ActiveRecord::Base    has_many :categories    has_many :meals, through: :categories  end    class Category < ActiveRecord::Base    has_many :meals  end    class Meal < ActiveRecord::Base    belongs_to :category  end  

What I am asking for is how to write the routes. Without nesting the links would look like:

restaurants GET      /restaurants(.:format)          restaurants#index  ....  menus GET            /menus(.:format)                menus#index  ....  categories GET       /categories(.:format)           categories#index  ....  

How am I then going to reach restaurants/1/menus/2/categories/3/meals/2 for example?

Rails routes: redirect an entire resource

Posted: 06 Jun 2016 06:11 AM PDT

I know about redirecting a specific route:

put 'users/:user_id', to: redirect('/api/v1/users/:user_id')  

How would I apply the redirect to all routes generated by resources? Looking for something like

resources :users, to: redirect('/api/v1')  

I can achieve a workaround using match, but it's a bit clunky:

match 'users/*path', to: redirect('/api/v1/users/%{path}'), via: [:GET, :POST, :PUT, :DELETE]  

Rails Project Chartkick with Highcharts

Posted: 06 Jun 2016 06:42 AM PDT

I am adding charts on my Rails application and I started using chartkick the variety of charts that it offers are not quite what I would like. I found in their documentation that you can use the Highcharts library. The issue is, I followed the steps but nothing happens... Does anyone know the correct way to use these two together?

Here is the code I write: <%= column_chart @prsd_data, xtitle: "Members", ytitle: " # of publications", width: "100%", height: "100%" %>

@prsd_data is a hash that contains as keys the names of some people and as values an array of 2 integers.s

NOTE: The chart I want to generate is something like this one : Highcharts

Adding tooltip in link_to tag in rail application

Posted: 06 Jun 2016 06:36 AM PDT

I have a link on the index.html.erb page. Its a download link. Now I want that if the cursor hovers on the link then a tooltip text will be displayed.e I have tried several combinations but did not get the solution yet.

My code is here:

<p>  Download:  <%= link_to "CSV", users_export_path(format: "csv") %> |  <%= link_to "Excel",users_export_path(format: "xls") %>  </p>  

I installed bootstrap and I want to generate bootstrap tooltip for this two links. Please tell what should I do along with right syntax.

Rails: How to calculate total amount in each currency

Posted: 06 Jun 2016 06:59 AM PDT

I'd like to calculate total amount in each currency.

My app image is as followings;

event1    USD 1.23  event2    EUR 2.34  event3    JPY 100  event4    USD 4.56    Total  USD 5.79  EUR 2.34  JPY 100  

Although I could calculate amounts with using sum(:amount) regardless of currency, I'd like to know how to calculate and display in each currency.

views\schedules\show.html.erb

<%= render @schedules %>  

views\schedules\ _schedules.html.erb

<% schedule.rooms.each_with_index do |a, idx| %>    <% a.events.each do |e| %>      <%= e.title %>      <%= e.ccy %> <%= e.amount %>    <% end %>      <%= a.events.sum(:amount) %>   # 108.13 regardless of currency (1.23 + 2.34 + 100 + 4.56)  

my models

class Schedule    has_many :rooms, inverse_of: :schedule, dependent: :destroy  end    class Room        belongs_to :schedule, inverse_of: :rooms    has_many :events, inverse_of: :room, dependent: :destroy  end    class Event    belongs_to :room, inverse_of: :events    has_one :schedule, autosave: false, through: :room  end  

controllers\schedules_controller.rb

def show    @schedules = Schedule.find(params[:id])  end  

schema.rb

create_table "rooms", force: :cascade do |t|    t.integer  "schedule_id"    t.integer  "day",                  default: 1  end    create_table "events", force: :cascade do |t|    t.string   "title"    t.integer  "room_id"    t.string   "ccy"    t.decimal  "amount"  end  

It would be appreciated if you could give me any suggestion.

How to get file with greatest number in filename within directory?

Posted: 06 Jun 2016 06:31 AM PDT

Consider I have a directory with the following files:

20151203073208_create_animals.rb  20151214130905_create_spoons.rb  20151230083444_create_cups.rb  20160226120137_create_humans.rb  20160321204759_create_trees.rb  

I need to get these digits 20160321204759.

However finding the last modified file doesn't apply here as any file withing the directory can be modified last.

For example:

Dir.glob(Rails.root.join('db/migrate/**.*')).max_by {|f| File.mtime(f)}  

produces

20151214130905_create_spoons.rb  

So how can I get number from filename with the greatest digits?

Google map not displaying on the first load

Posted: 06 Jun 2016 06:04 AM PDT

I'm trying to follow this tutorial for loading a gpx file but with rails 4.2.6. I've got it working but I have a problem that when I load the tracks#index view and I click on the track to see it, it doesn't load the Google Map (the rest of the page loads) but if I right click on the link and open it in another tab or type the url myself it loads the Google Map fine.

The track#index view was generated with scaffolding:

<%= link_to track_path(track), class: 'btn btn-xs', title: "#{ t('.show', default: t('helpers.links.show')) }" do %>          <%= glyph 'info-sign' %>        <%- end -%>  

When I click on it calls the tracks#show controller:

  def show  @track = Track.find(params[:id])  respond_to do |format|    format.html      format.json {      render :json => @track.to_json(:methods => [:polyline],:only => [:name])    }  end  

end

polyline is just a method for encoding the gpx points as a polyline using the Polyline gem.

The tracks#show view load the map with:

<div id="map_canvas" style="height: 200px; margin-bottom: 20px"></div>  

The initialization code for the maps is in coffeescript:

gm_init = ->    gm_center = new google.maps.LatLng(38, 0)    gm_map_type = google.maps.MapTypeId.SATELLITE     map_options = {center: gm_center, zoom: 8, mapTypeId: gm_map_type}    new google.maps.Map(@map_canvas,map_options);  $ ->    map = gm_init()  

What I don't understand is why when loading /tracks/1 works ok when the clicking on the index to load the same url it doens't show the mat just and empty area

invoke slim instead of erb in rails 4.2.6

Posted: 06 Jun 2016 05:36 AM PDT

I have been trying to use default template engine as slim. But what ever the way i try i get erb instead of slim. I used

gem 'slim-rails'  

as suggested but that didnt work. I have added this piece of code in my application.rb as suggested

config.generators do |g|    g.template_engine :slim  end  

this didnt work. I have been trying to configure devise views with this command

rails g devise:views  

This always invokes erb. How to invoke slim template engine instead of erb.

Notify user about unread message using Layer Webhook

Posted: 06 Jun 2016 05:31 AM PDT

I know that Webhook can be implemented in Layer. There seems to be an event called 'message.sent' and 'message.read'. I am wondering how I can integrate a webhook for the following situation:

There are unread message in a conversation for over 5 minutes, then platform will send an email to the user.

Ruby on Rails - Gem "Therubyracer" installation after ruby 2.3.0 version update

Posted: 06 Jun 2016 06:01 AM PDT

I updated my Ruby from 1.9.3 to 2.3.0. Now i try to make bundle install, but the gem "Therubyracer" make an error.

Error :

C:\SVN\FOS\branches\FOS_5_0>gem install therubyracer  Fetching: libv8-3.16.14.15.gem (100%)  Temporarily enhancing PATH to include DevKit...  Building native extensions.  This could take a while...  ERROR:  Error installing therubyracer:          ERROR: Failed to build gem native extension.        current directory: C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8  C:/Ruby23/bin/ruby.exe -r ./siteconf20160606-1212-1uwfv1y.rb extconf.rb  creating Makefile  The "patch" command is misspelled or could not found.  C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:15:in `block (2 levels) in patch!': failed to apply patch C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/patches/disable-building-tests.patch (RuntimeError)          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:12:in `each'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:12:in `block in patch!'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:8:in `open'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:8:in `patch!'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/builder.rb:57:in `block in build_libv8!'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/builder.rb:54:in `chdir'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/builder.rb:54:in `build_libv8!'          from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/location.rb:24:in `install!'          from extconf.rb:7:in `<main>'  Applying C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/patches/disable-building-tests.patch    extconf failed, exit code 1    Gem files will remain installed in C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15 for inspection.  Results logged to C:/Ruby23/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/libv8-3.16.14.15/gem_make.out  

gem_make.out :

current directory: C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8  C:/Ruby23/bin/ruby.exe -r ./siteconf20160606-1212-1uwfv1y.rb extconf.rb  creating Makefile  The "patch" command is misspelled or could not found.  C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:15:in `block (2 levels) in patch!': failed to apply patch C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/patches/disable-building-tests.patch (RuntimeError)      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:12:in `each'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:12:in `block in patch!'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:8:in `open'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/patcher.rb:8:in `patch!'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/builder.rb:57:in `block in build_libv8!'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/builder.rb:54:in `chdir'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/builder.rb:54:in `build_libv8!'      from C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/ext/libv8/location.rb:24:in `install!'      from extconf.rb:7:in `<main>'  Applying C:/Ruby23/lib/ruby/gems/2.3.0/gems/libv8-3.16.14.15/patches/disable-building-tests.patch    extconf failed, exit code 1  

How can i fix this problem, because the server wants this gem for start?

How to store Access Token from my API in the sample client App and intercat with it

Posted: 06 Jun 2016 05:19 AM PDT

I have two Ruby on Rails projects: 1) API, 2) Sample Client App.

My API support Oauth2 Resource Owner Password flow (so no redirect URI). Just Client Credentials (Key + Secret) and username + password. The result of the authentication is the Access Token.

Now I need to implement common login form and profile dashboard on the Sample Client App. Key and secret will be hardcoded in the project. I can call authentication endpoint, but I don't know how to store the access token and how to interact with it when user will work with his profile (change his password for example) for example. Do I need to store it in the session object? Or there is another way ??

Thanks for the help.

Android Push Notification using firebase from ruby on rails

Posted: 06 Jun 2016 05:15 AM PDT

How to send push notification to Android Mobile using firebase from ruby on rails. I know rails-push-notifications and others but I want using firebase so kindly provide documentation for how to send push notification using firebase in android application.

if exists overwrite with new data else create new row in rails

Posted: 06 Jun 2016 06:52 AM PDT

I am using Ruby 2 and Rails 4. I want to create new data if the 'name' does not exist, and if it exists then update with new data. From my picture, if 'lol' exists, update new pdf file when uploading else create new row with new data. How can I do this? Please share with me if any has any idea.

enter image description here

My codes are: Static_pages controller:

def create_form      @form_downup = Contact.new(contact_params)      if @form_downup.save          redirect_to :back      else        redirect_to downloads_form_path      end    end     private      def contact_params         params.require(:contact).permit(:name,:file)        end  

downloads_form.html.erb

<table class="table table-condensed table-responsive">          <tbody>              <%= form_tag create_form_path,  multipart: true  do |f| %>              <tr>                                  <td class=""><%= text_field_tag "contact[name]", nil, class: "form-control" %></td>                  <td><%= file_field_tag "contact[file]",  class: "form-control" %></td>                  <td><%= submit_tag 'Upload' %></td>                  <td><%= link_to "Download", static_pages_downloadform_pdf_path(:file_name => "lol") %></td>                </tr>                    <% end %>             </tbody>      </table>  

Ruby on rails. Deployment fails because markerclusterer not found

Posted: 06 Jun 2016 05:05 AM PDT

I am trying to deploy to elasticbeanstalk but deployment fails with Sprockets::FileNotFound: couldn't find file 'markerclustererplus/src/markerclusterer_packed.js' with type 'application/javascript'

Recently Google changed it's sources and I followed this guide to re-enable the markerclusterer javascript.

Everything works correctly in development but fails when deploying. If I remove the lines

#= require markerclustererplus/src/markerclusterer_packed.js from application.js.erb then the app deploys but obviously the map doesn't work.

I can see that vendor/assets/google-maps-utility-library-v3/markerclustererplus/src/ markercluster_packed.js DOES exist. I suppose this is why it works in development, but I have no idea why it fails on deployment.

Now, maybe I'm doing something wrong as the very last line of the tutorial git submodule update — init fails for me with the error:

error: pathspec '—' did not match any file(s) known to git.  error: pathspec 'init' did not match any file(s) known to git.  

I didn't think much of it as development env works fine, but maybe it has something to do with my problem. This is the first time i've ever dealt with submodules in git so I may well be missing something.

dailyLimitExceededUnreg: Daily Limit for Unauthenticated Use Exceeded

Posted: 06 Jun 2016 04:56 AM PDT

Note: Before Posting i read similar questions in stack overflow.

Hi, I am using google-api-client -v '0.9.8' newer i am getting issue

client_secrets = Google::APIClient::ClientSecrets.load("/home/secrets.json")  @auth_client = client_secrets.to_authorization          @auth_client.update!(            :scope => 'https://www.googleapis.com/auth/calendar',            :access_type => "offline", #will make refresh_token available            :approval_prompt =>'force',            :redirect_uri => 'http://someurl.com'          )   url = @auth_client.authorization_uri   link = "https://accounts.google.com/o/oauth2/auth?#{url.query}"   

when you click on link a url will it will be redirected to a page where code will be genrated

@auth_client.code = "generated code"  @auth_client.fetch_access_token!  

To Generate access_token and refresh_token

service = Google::Apis::CalendarV3::CalendarService.new  response = service.list_events('primary',max_results: 10,single_events: true,order_by: 'startTime',time_min: Time.now.iso8601)  

This point issue will arise

dailyLimitExceededUnreg: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.  

FYI I enabled google calendar api in google developer console.

If anyone resolved this issue please let me know.

Rails - update variable attribute with dropdown and without save button

Posted: 06 Jun 2016 04:58 AM PDT

I have a table which shows some Leads that are linked to the current user. In this table I have a field "status" which I would like to have as a dropdown. When you select another status in this dropdown, it immediately saves that status for that lead without having to click a "save"-button.

Can someone help/guide me on implementing this?

Thanks in advance, Thomas

Rails ActiveRecord Timestamp in Epoch instead of DateTime

Posted: 06 Jun 2016 04:15 AM PDT

Need to store created_at and updated_at timestamps in Epoch instead of Time Stamp. Is there a way to alter the default behaviour while having ORM to do it's job to maintain the timestamp.

I know that I can directly create a column, and manually create and update everytime the record changes, But that's going to be lot of bad code redundant code introduced in the application.

Thanks

Amazon s3 prices

Posted: 06 Jun 2016 06:17 AM PDT

I've read about amazon pricing here. https://aws.amazon.com/s3/pricing/?nc1=h_ls So I will have a e-commerce shop with 10 000 items. I will need Amazon s3 for item's photo storage.

So I will have have around 10 000 photos on amazon s3. Right now I wonder: PUT, COPY, POST, or LIST Requests $0.0054 per 1,000 requests

So if I upload all photos to aws3 manually and I will upload all 10 000 files at one time. Will I be charged like 0.0054 * 10 000 = $54 or the calculations here are a little bit different? UPATE:

I don't know why you are downvoting me. I just wonder if manually putting file to aws3 counts as put request and if I put 10 files there by drag and dropping them from my computer - will it count as one request or many.

undefined method operators on legal Postgresql database

Posted: 06 Jun 2016 05:14 AM PDT

I'm beginner, so sorry if i ask for something trivial.

Two tables imed_patient and imed_operator are legal Postgresql tables with relation between them (many patients to one operator by r_opr_code field in imed_patient), described by definitions:

class ImedOperator < ActiveRecord::Base        self.table_name = "imed_operator"     self.primary_key = "code"     belongs_to :ImedPatient   end     class ImedPatient < ActiveRecord::Base     self.table_name = "imed_patient"      self.primary_key = "code"     has_one :ImedOperator, :foreign_key => "r_opr_code"  end  

I want to view all patients with data (ex. name, surname) from imed_operator (details of patients), so I produced pacjenci_controller.rb

class PacjenciController < ApplicationController       def index               @patients = ImedPatient.all               @operator = @patients.operators          end      def show            @patient = ImedPatient.find(params[:id])       end   end  

In web broweser I receive error :

NoMethodError in PacjenciController#index  undefined method `operators' for #<ImedPatient::ActiveRecord_Relation:0x007fbb269ffe00>  

Extracted source (around line #5): @operator = @patient.operators

UPDATE:

my index.html.erb

<h1>Pacjenci w Optimed</h1>    <table>    <tr>      <th>Nazwisko</th>      <th>ImiÄ™</th>      <th>Pesel</th>      <th>Code_operator</th>      <th>Wizyty</th>      <th></th>      <th></th>    </tr>    <% @patients.each do |patient| %>    <tr>      <td><%= link_to @operator.surname, controller: "pacjenci", action: "show", id: patient.r_opr_code %></td>       <td><%= @operator.first_name %></td>       <td><%= @operator.pesel %></td>       <td><%= patient.r_opr_code %></td>      <td><%= link_to 'Wizyty', url_for(action: 'wizytypacjenta', controller: 'wizyty', id: patient.code) %></td>     </tr>  <% end %>  </table>    <br>    <p><%= link_to 'Start', url_for(action: 'index', controller: 'pacjenci') %></p>  <p><%= link_to 'Wstecz', url_for(:back) %></p>  

And I stucked :(

Data scraping form input snag rails

Posted: 06 Jun 2016 04:01 AM PDT

Building a website which datascrapes the UCAS website for universities and courses, we're trying to limit it to only universities from Scotland, but the below code doesn't seem to work. Location in the form is the name of the input id for that segment of the form on the ucas website but as it is now it still displays all universities.

  class PagesController < ApplicationController        def home      require 'mechanize'      mechanize = Mechanize.new    @uninames_array = []    page = mechanize.get('http://search.ucas.com/')    form = page.forms.first  form['Vac'] = '2'  form['AvailableIn'] = '2016'  form['Location'] =  'scotland'  page = form.submit    page.search('li.result h3').each do |h3|  #  puts h3.text.strip    end    while next_page_link = page.at('.pager a[text()=">"]')    page = mechanize.get(next_page_link['href'])    page.search('li.result h3').each do |h3|  #    puts h3.text.strip  name = h3.text    @uninames_array.push(name)    end  end    end      end  

Rails calling the class itself with parameters

Posted: 06 Jun 2016 04:10 AM PDT

I am writing some wrapper to an external service Layer. I would like to create some helpers like Layer::CreateIdentity(uid) and Layer::UpdateIdentity(uid). In which I will use layer-api gem and do some logic inside.

I will put these helpers in lib/layer/create_identity.rb etc.

When designing the class, I don't want to do something like Layer::CreateIdentity.new(uid).call. Rather I just want to do Layer::CreateIdentity(uid).

Is there ways of achieving this?

Is there a possible way to set price limit at amazon s3

Posted: 06 Jun 2016 04:24 AM PDT

Is there a possible way to set price limit at amazon s3. I've read about creating an alarm here http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/free-tier-alarms.html But It seems like an alarm when you exceed your free limits. And I need to set amount of money for example to $10 and if bill is more than that - terminate service usage.(In case of dos attack for example I might notice email alarm too late, or I might be travelling and don't have access to internet or whatever)

Using different assets for a different namespace in Rails 4

Posted: 06 Jun 2016 04:10 AM PDT

I have a Rails 4 app that uses the assets in app/assets/javascripts and app/assets/stylesheets throughout the application. However, I have made a nested resource for the admin portion of the app. I'd like for the admin interface to differ from what the end-user sees (different layout, different assets).

I tried changing the following in my application.css file:

*= require_tree .  

to

*= require_directory  

but the entire app still seems to be using the same resources. Could anyone please illuminate me on how to use different assets for different portions of a Rails 4 app?

Custom config from YAML not initialised properly in Rails

Posted: 06 Jun 2016 05:38 AM PDT

I want to load YAML file with credentials and make it accessible via Rails.application.config.my_service. I have initializer in my_service.rb:

Rails.application.config.my_service = OpenStruct.new(YAML.load_file(Rails.root.join('config', 'my_service.yml'))[Rails.env])  

The YAML file:

development: &defaults    app_1_id: 9304    app_2_id: 2323    staging:    <<: *defaults    test:    <<: *defaults    production:    app_1_id: 1234    app_2_id: 8328  

The issue is that when I call Rails.application.config.my_service.app_1_id then I get correct value, but for Rails.application.config.my_service.app_2_id I get nil. So only the first line of YAML config works.

Would appreciate any hint.

Css overwrite list styles

Posted: 06 Jun 2016 03:37 AM PDT

I have in my rails app reset.css with

ul, ol, li { list-style: none; }

but i don't want to have it on some pages,i want to keep it default(default css styles)

How can i set default values for it?

my div with list

 <div class="text_blog">      <ol>       <li>1</li>       <li>2</li>       <li>3</li>      </ol>     </div>  

it can be olor ul list

No comments:

Post a Comment