ruby-on-rails-3.2

Ruby on Rails joins models for json output

风流意气都作罢 提交于 2019-12-10 12:15:30
问题 I'm trying to build a JSON API end point with Ruby on Rails. I followed the instruction in the following and was able to create JSON API for my models http://railscasts.com/episodes/350-rest-api-versioning?view=comments/ I have the following controller: /api/v1/movies_controller.rb class MoviesController < ApplicationController def index if params[:p].nil? p = 1 else p = params[:p].to_i end @movies = Movie.order("id DESC").page(p) end def show @movie = Movie.find(params[:id]) end end I need

Simple_form input as both text and autocomplete

天涯浪子 提交于 2019-12-10 12:06:21
问题 I am using gem 'simple_form', '2.0' and gem 'rails3-jquery-autocomplete', '1.0.10'. I am unable to make a string field accept two ':as' arguments. <%= f.input :product_description , :url => autocomplete_product_name_products_path, :as => :text, :as => :autocomplete, :placeholder=>"Type product name", :input_html => {:class =>"span2", :rows => 6}, wrapper: :inline_label, label:false %> If I remove :as => :text, the auto-complete part works but ':rows => 6' part fail. And if I keep both, I get

rails: devise update user without password

て烟熏妆下的殇ゞ 提交于 2019-12-10 10:41:37
问题 I've followed the directions in devise's wiki regarding overriding update method to update user information without adding password, but I'm still getting notice saying that I can't leave password blank. I'm stuck and I need some assistance on tracking the problem down. <%= form_for(resource, :as => resource_name, :url => custom_update_user_registration_path, :html => { :method => :put }) do |f| %> <%= devise_error_messages! %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%

How to redirect after a successful AJAX form submission (Rails 3.2)

China☆狼群 提交于 2019-12-10 10:27:30
问题 Suppose you have an edit form with :remote => true . Your controller method looks like def update @article = Article.find(params[:id]) respond_to do |format| if @article.update_attributes(params[:article]) format.html { redirect_to @article} format.js { render :js => "window.location.replace('#{article_path(@article)}');"} else format.html { render :action => "edit" } # Render update.js.erb which replaces the body of the form format.js {} end end end What's the best way to do the redirect on

Can the Liquid Ruby template engine deal with Rails forms?

这一生的挚爱 提交于 2019-12-10 09:46:31
问题 I've been searching for a template engine to allow users to create lessons and exercises online easily. Seems like Liquid is the most popular for use in Rails. Can Liquid users easily create rails forms? Normally I create forms in ERB with: <%= form_for(@lesson) do |f| %> <% if @lesson.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@lesson.errors.count, "error") %> prohibited this lesson from being saved:</h2> <ul> <% @lesson.errors.full_messages.each do |msg| %> <li><%= msg %>

Why is assets:precompile so slow on Heroku?

那年仲夏 提交于 2019-12-10 08:29:16
问题 My deployment set up is to have Heroku precompile assets. I want them precompiled so I can send them to a CDN (via asset_sync) and I want that done on Heroku so I don't have any compiled assets in my repo. I set that up using Heroku's guide and that had been working great. I added turbo-sprockets-rails3 for a speed boost. It had all been working fine and then stopped; I can't figure out why. Now when I deploy (without public/assets ) the assets:precompile Rake task times out on Heroku. To see

Select tag with multiple values pre-selected - Values inserted manually in database

∥☆過路亽.° 提交于 2019-12-10 04:24:40
问题 I have a problem, I don't planned my database correctly, so always I need to use 'alternatives'. I want pre-selected multiple values in select_tag. But I'm adding the vacancies 'manually' in table vacancy. My controller: def create @hr_curriculum_generic = HrCurriculumGeneric.new(params[:hr_curriculum_generic]) # Tabela CandidatosxVagas unless params[:vacancy_ids].nil? @vacancies_ids = params[:vacancy_ids] -- my form: @vacancies_ids.each do |vacancy_id| # Armazena os id do curriculum, vaga e

RSolr::Error::InvalidRubyResponse - 200 OK

别来无恙 提交于 2019-12-10 03:24:36
问题 I am getting following error even after starting forreman and starting sunspot:solr : RSolr::Error::InvalidRubyResponse - 200 OK Error: <result status="1">java.lang.NullPointerException at org.apache.solr.handler.XmlUpdateRequestHandler.doLegacyUpdate(XmlUpdateRequestHandler.java:129) at org.apache.solr.servlet.SolrUpdateServlet.doPost(SolrUpdateServlet.java:87) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at

Retrieve the nextval from a sequence using activerecord in Ruby on Rails 3.2.14 / Ruby 2.0.0 / PostgreSQL 9.2.4

时光毁灭记忆、已成空白 提交于 2019-12-10 01:44:10
问题 This should be SO simple. I want to retrieve the nextval of a sequence... it's not a default value... it's not a primary key... it's not a foreign key. In rare cases, I need a sequence number for a user supplied value. I've tried the following: @nextid = ActiveRecord::Base.connection.execute("SELECT nextval('xscrpt_id_seq')") and what I get back is: #<PG::Result:0x007fe668a854e8 @connection=#<PG::Connection:0x00000003aeff30>> And by using @nextid[0]["nextval"] I can get the correct value, but

Getting Ruby on Rails environment working and installing sqlite3

时间秒杀一切 提交于 2019-12-09 18:48:02
问题 Trying to upgrade to the latest version of Ruby on Rails. I got ruby and rails installed ok (I think). C:\Users\benjaminw>ruby --version ruby 2.0.0p0 (2013-02-24) [x64-mingw32] C:\Users\benjaminw>rails -v Rails 3.2.13 I'm following an instructional guide out of a Ruby on Rails book but it's a little out of date. The next step says to download the sqlite3 db and extract the the files to the following folder C:/Ruby200/bin Then run the following command to make sure the db was installed