ruby-on-rails-3

No Javascript runtime on windows when running rails server

☆樱花仙子☆ 提交于 2020-01-25 02:21:26
问题 I'm completely new to Ruby on Rails, and I'm having trouble setting it up on my Windows PC . I have successfully followed the instructions on http://rubyonrails.org/download. However, when I go to run the rails server command I come up with this output: C:/Ruby192/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `a utodetect': Could not find a JavaScript runtime. See https://github.com/sstephen son/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from C:

Entry level javascript with rails: updating a div on form submit (3.1/jquery)

我的梦境 提交于 2020-01-25 01:01:47
问题 I have a basic page, with a div containing text, and a form to update that text, on rails 3.1/jquery. I do not know jquery or js well so I'm just poking about with the coffeescript for the controller. None of the tutorials I've found seem be relevant, and the few I've found are ancient. I can see what is going on, sort of: I can get an js alert on ajax success, for the form as a remote form (that puts to the server and the update on the controller works -- the basic text gets changed, but I

How do I render sass in a rails partial?

送分小仙女□ 提交于 2020-01-25 00:16:06
问题 I have a Rails 3.2 app. I'm trying to render processed sass code in a partial. I have added an initializer to handle scss files: ActionView::Template.register_template_handler :scss, Sass::Rails::ScssTemplate My sass file is called _style.scss and the render call looks like: <%= render partial: "./templates/default/style", formats: "css" %> I get the following error: undefined method `call' for Sass::Rails::ScssTemplate:Class To me, this looks like Rails doesn't know how to handle the Sass

Find tags with articles

强颜欢笑 提交于 2020-01-24 23:34:25
问题 On blog app I want to display list of tags with articles. class Article < AR::B has_and_belongs_to_many :tags end class Tag < AR::B has_and_belongs_to_many :articles end What would Tag scope look like? Tag.joins(:articles) ... # should return tags associated to at least 1 article 回答1: One way to do this with Ruby/Rails would be this one. Tag.includes(:articles).select { |tag| tag.articles.any? } .includes makes sure that the articles are loaded alongside the tags, which is more efficient than

missing gems can

回眸只為那壹抹淺笑 提交于 2020-01-24 20:06:09
问题 Bundler could not find compatible versions for gem "railties": In Gemfile: rails (= 3.2.3) ruby depends on railties (= 3.2.3) ruby jquery-rails (= 2.0.0) ruby depends on railties (3.2.5) I have got that error message while trying to "bundle install" and here is my gemfile source 'https://rubygems.org' gem 'rails', '3.2.3' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' group :development do gem 'sqlite3', '1.3.5' end gem 'json' # Gems used only for

Eventbrite authentication using OAuth2.0 Rails

萝らか妹 提交于 2020-01-24 19:54:12
问题 Iam creating an application where I am trying to authentivate a user with eventbrite. With reference of doc I include the javascript in my application and it generates a CONNECT WITH EVENTBRITE link in my app. When I click this button It takes me to the url: https://www.eventbrite.com/oauth/authorize?response_type=token&client_id=xxxxxxxxxxxx (Here client id is the eventbrite app key of my application.) When the user ALLOWS the application to access the evenbrite account it redirects me to my

Trying to delete a file with the AWS gem

折月煮酒 提交于 2020-01-24 17:23:25
问题 In rails console, I do: s3 = Aws::S3.new(APP_CONFIG['amazon_access_key_id'], APP_CONFIG['amazon_secret_access_key']) s3.delete('bucketname', 'uploads/users/14/photo/33/foo.jpg') I get: NoMethodError: undefined method `delete' for #<Aws::S3:0x0000010650b228> I read this doc. Am I missing something? 回答1: s3 = Aws::S3.new(APP_CONFIG['amazon_access_key_id'], APP_CONFIG['amazon_secret_access_key']) s3.bucket('bucketname').delete_key('uploads/users/14/photo/33/foo.jpg') 来源: https://stackoverflow

respond_to only format.js for all mime types

孤街浪徒 提交于 2020-01-24 06:57:11
问题 I have a controller which respond_to format.js, however, most request assume the old format.html still exists and throws a 404 exception. How do I capture all MIME request on the controller and redirect them only to format.js? Here's the current controller action def search respond_to do |format| unless @search.nil? format.js { render :partial => '/search/search_form', :status => 200 } else format.js { render :partial => '/search/not_exist', :status => 500 } end end end I'm trying to do

How can I get all list of scopes in ActiveRecord 3.x

旧城冷巷雨未停 提交于 2020-01-24 02:50:07
问题 I am using ActiveRecord with Rails 3. I defined scopes in my model. How can I get the list of all scopes of that model? Previously I could use Model.scopes OR Can I check a scope is defined or not? Something like Model.scope_defined?("scope_name") Thanks in advance. 回答1: You can see if a scope is defined or not this way Model.send(:valid_scope_name?, :scope_name) it will return true if it does exist and nil if it does not. If you check the source code of valid_scope_name?, you see that you

find_or_create on a has many through relationship

孤街醉人 提交于 2020-01-24 02:26:11
问题 I have a has many through relationship in my app: Shows has many Bands through => Lineups Bands are unique by :name class Show < ActiveRecord::Base attr_accessible :city_id, :title, :dateonly, :timeonly, :image, :canceled, :venue_attributes, :bands_attributes belongs_to :city belongs_to :venue has_many :lineups has_many :bands, through: :lineups has_and_belongs_to_many :users end class Lineup < ActiveRecord::Base belongs_to :show belongs_to :band end class Band < ActiveRecord::Base attr