ruby-on-rails-3

How to call javascript file in Ruby On Rails

ⅰ亾dé卋堺 提交于 2019-12-23 05:08:13
问题 I have two Layouts and each layout have different CSS and Js files. while i use <%= javascript_include_tag 'application' %> then, it brings all .js files. Is anything available like following way: <%= javascript_include_tag 'folder/script1.js' %> <%= javascript_include_tag 'folder/script2.js' %> <%= javascript_include_tag 'folder/script3.js' %> ... Is there a way to only include all scripts in an specific folder? Thanks. 回答1: Create a new file application_foo.js with the following content; //

How do I show formatted text in rails text area?

时光怂恿深爱的人放手 提交于 2019-12-23 04:57:19
问题 I'm using rails form. In that form, I've a text_area. I want to show pre-filled data in text area of rails. The data is html content. I tried following, <% test_val= "<h1>Test Value</h1>" %> <%= form.text_area(:myval, :value => test_val.html_safe, size: '30x10', :style => 'border: 10;') %> myval is my form variable. But instead of printing Test Value in bold and bigger font in text area, t showed <h1>Test Value</h1> . I want the content in HTML tag to be printed with HTML formatting. Is it

How to ignore case when sorting a column

扶醉桌前 提交于 2019-12-23 04:54:09
问题 When I sort the name column of a model in ActiveAdmin , I get output such as the following: Apples Icicles Zebras iMacs iPhones where the uppercase and lowercase letters appear to be sorted separately. I prefer to display sorted columns in the following manner: Apples Icicles iMacs iPhones Zebras with no unnatural case sensitivity. I tried using the line column :name, sortable: 'my_model.name.downcase' to mitigate the issue, but this throws an ActiveRecord::StatementInvalid error. How can I

Table seems lost when I try to I define a 'Campus' model in rails and set the plural name myself

喜欢而已 提交于 2019-12-23 04:49:23
问题 I need a table whos name is Campus. But rails interprets that as plural, messing everything up. So I did a little research and they suggest to add an inflection like this: ActiveSupport::Inflector.inflections do |inflect| inflect.singular /^(campus)(es)?$/i, '\1' inflect.plural /^(campus)$/i, '\1es' end I have added this in the initializers/inflection.rb file. I created a new migration to drop the table and create a new one again called Campus, expecting to have the problem solved, but now I

How to use Twitter gem in Rails, need small to figure out the whole thing?

懵懂的女人 提交于 2019-12-23 04:38:26
问题 I got access for the user using twitter_auth gem. Here is the code for that. def twitter client = TwitterOAuth::Client.new( :consumer_key => '******', :consumer_secret => '********' ) request_token = client.request_token(:oauth_callback => new_user_url) session[:request_token] = request_token redirect_to request_token.authorize_url end def new client = TwitterOAuth::Client.new( :consumer_key => '*****', :consumer_secret => '******' ) access_token = client.authorize( session[:request_token]

How to use Twitter gem in Rails, need small to figure out the whole thing?

烈酒焚心 提交于 2019-12-23 04:38:20
问题 I got access for the user using twitter_auth gem. Here is the code for that. def twitter client = TwitterOAuth::Client.new( :consumer_key => '******', :consumer_secret => '********' ) request_token = client.request_token(:oauth_callback => new_user_url) session[:request_token] = request_token redirect_to request_token.authorize_url end def new client = TwitterOAuth::Client.new( :consumer_key => '*****', :consumer_secret => '******' ) access_token = client.authorize( session[:request_token]

Is Spree extensible enough to support multiple vendors in one app just like Amazon.com?

孤街醉人 提交于 2019-12-23 04:36:15
问题 In short, is it possible to build an Amazon clone without substantial modification to Spree? 回答1: it is indeed possible. If you do, don't use spree as an engine, just use the whole sourcecode as itself. If you use it as an engine, you'll end up overriding so much features of spree that you will be lost totally! Also use and extend the tests that come with spree. You will however loose the ability to update spree, because you will have to change a lot of stuff in the core. 来源: https:/

Rspec is giving an error with my layout links from the rails tutorial: “Failure/Error: Unable to find matching line from backtrace”

独自空忆成欢 提交于 2019-12-23 04:32:29
问题 Same question, but solution did not work:, I've tried several versions of rspec: Why is Rspec saying "Failure/Error: Unable to find matching line from backtrace"? dpalacio:sample_app dpalacio$ rspec -v 2.0.0.beta.18 dpalacio:sample_app dpalacio$ rspec spec/ controllers/ factories.rb models/ requests/ spec_helper.rb dpalacio:sample_app dpalacio$ rspec spec/requests/ FFFFF Finished in 0.55501 seconds 5 examples, 5 failures 1) LayoutLinks should have a Home page at '/' Failure/Error: Unable to

What is the scope of Ruby code in a js.erb file and how can it access controller variables

人走茶凉 提交于 2019-12-23 04:28:26
问题 I have a js.erb file in which I want to use asset_path. It is included in a view like this: <%= javascript_include_tag "resources/gallery_resource" %> This works fine while the asset path is self contained, however I need to use a variable defined in the controller (@resource) inside the asset path: element.image = "<%= asset_path 'resources/galleries/'+@resource.uid+'/'+index+'.jpg' %>" The problem being @resource is not defined. So what is the scope of this Ruby code if it doesn't have

Error trying to download using filnename format

荒凉一梦 提交于 2019-12-23 04:28:25
问题 I'm trying to customize the format when i'm saving to xls : I want help customizing= "Date" + "ejecutive selected" + ".xls" But is not working My models class Policy < ActiveRecord::Base unloadable belongs_to :ejecutive has_many :policy def self.search(search) if search find(:all, :conditions => ["ejecutive_id = ? ", search.to_i ] ) else find(:all) end end end class Ejecutive < ActiveRecord::Base has_many :policies end Here is my controller. Here i put my format that i'm trying to customize