ruby-on-rails-3.2

how to use rails format.json [closed]

流过昼夜 提交于 2020-01-22 13:55:09
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . def index @cellphones = Cellphone.all respond_to do |format| format.html # index.html.erb format.json { render json: @cellphones } end

Use active_model_serializer with a non-ActiveRecord object

我们两清 提交于 2020-01-22 08:19:25
问题 I have a model object that is not descended from ActiveRecord::Base and is not stored in the database. I created a serializer for it (with the same name + "Serializer"), and in my controller I'm calling render json: object_instance . The result is an exception from deep inside of render . I implemented an as_json method that instantiates the serializer and calls it, but the result is then a missing method in the object, read_attribute_for_serialization . I want my object to act like an

Savon create matched XML pattern

本小妞迷上赌 提交于 2020-01-17 08:15:12
问题 I am trying to get the pan info from the income tax of india web API. The standard XML for the request is this <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pan="http://panws.dit.tcs.com/" xmlns:typ="http://panws.dit.tcs.com/types/"> <soapenv:Header/> <soapenv:Body> <pan:getPanInfo> <login> <typ:userName>xxxxxxxxx</typ:userName> <typ:password>xxxxxxxxxx</typ:password> </login> <panNo> <typ:panNo>xxxxxxxxxxxxx</typ:panNo> </panNo> </pan:getPanInfo> </soapenv

OS X rails3 postgresql cannot create database not recognizing its default username

人盡茶涼 提交于 2020-01-16 19:36:26
问题 On a machine running OS X 10.6 a rails 3.2 environment is attempting to create the databases, but failing. Rake gems tested: include 0.9.2.2 (installed by some dependency) and a declared 10.0.4. username is defined in database.yml Couldn't create database for {"adapter"=>"postgresql", "database"=>"app_development", "username"=>"postgres"} FATAL: role "postgres" does not exist Yet, this is not the first application on the machine. All other applications connect to the postgre cluster with that

cannot load such file — pty (LoadError)

主宰稳场 提交于 2020-01-16 04:24:13
问题 Completely new to Ruby on Rails. My environment is Windows 2008 R2, and I just use the RailsInstaller to set it up. I was given a website, so I placed it under C:\Sites. I followed the guide, and installed rails, as you can see the version down there in the code. Then I ran "rails server" to try to start the service, but I was given error message about "therubyracer-heroku-0.8.1.pre3 not installed, so I did a gem install and bundle install after that. Then therubyracer-heroku threw bunch of

Failed to build gem native extension ruby racer gem of different version

感情迁移 提交于 2020-01-16 01:31:29
问题 I copied the application from production and did bundle install to install all the missing gems that are in production version and not on my local machine. Gem.lock file has the rubyracer version '0.10.1'. So when it tried to install this version using bundle install following error appeared. Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/user/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb *** extconf.rb failed *** Could not create Makefile due to

Failed to build gem native extension ruby racer gem of different version

空扰寡人 提交于 2020-01-16 01:31:11
问题 I copied the application from production and did bundle install to install all the missing gems that are in production version and not on my local machine. Gem.lock file has the rubyracer version '0.10.1'. So when it tried to install this version using bundle install following error appeared. Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/user/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb *** extconf.rb failed *** Could not create Makefile due to

How to suppress backtrace in Rails?

拈花ヽ惹草 提交于 2020-01-16 01:30:11
问题 When exiting a Rails app using raise or fail , how to prevent the backtrace from being displayed? Tried using back_trace_limit but it only seems to work for the console...? 回答1: You have total control over the backtrace returned with an exception instance by using its set_backtrace method. For example: def strip_backtrace yield rescue => err err.set_backtrace([]) raise err end begin strip_backtrace do puts 'hello' raise 'ERROR!' end rescue => err puts "Error message: #{err.message}" puts

How to do browser-based new user approval by Admin in Rails 3.2 using Devise

做~自己de王妃 提交于 2020-01-16 01:15:52
问题 I created a simple directory using Rails 3.2 and devise where new users need approval before they can use the site. I followed the instructions in "How To: Require admin to activate account before sign_in" and admin users can now see lists of different index pages of approved versus non-approved users. So far so good. My problem is the user approval process. Currently I approve users in the Rails console. I'd like for admin users to be able to approve users through their browser. I'm at a

Rails namespaced routes to wrong Controller

≯℡__Kan透↙ 提交于 2020-01-15 15:25:48
问题 So I'm just beginning with RoR and figured I do a basic blog with API endpoints aswell. The problem is that my api requests seem to be routed to the wrong controller, I have the following as my routes.rb Blog::Application.routes.draw do namespace :api do namespace :v1 do resources :articles end end end I also have controllers/api/v1/articles_controller.rb , which has the following content: module API module V1 class ArticlesController < ApplicationController respond_to :json def index respond