ruby-on-rails-3.1

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

感情迁移 提交于 2019-12-05 08:28:55
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 do cargo na tabela CandidatosxVagas @candidates_vacancies = CandidatesVacancy.new <% @vacancies =

How to hide html div

我的未来我决定 提交于 2019-12-05 08:13:01
I'm developing a small application in Ruby-On-Rails. I want to hide a div in an html.erb file until a link is clicked. What is the simplest way to do this? In your html file: <a href="#" id="show_whatever">Show Whatever</a> <div id="whatever" class="hidden">...</div> In your CSS file: div.hidden { display: none; } In an included javascript file, or inside of <script> tags: $(function() { $('a#show_whatever').click(function(event){ event.preventDefault(); $('div#whatever').toggle(); }); }); The hidden class is hiding the div. The jQuery function is listining for a click on the link, then

Is Rails 3.1 Edge breaking XmlMarkup::Builder?

半城伤御伤魂 提交于 2019-12-05 07:58:23
There are a number of examples on the Web (such as http://techoctave.com/c7/posts/32-create-an-rss-feed-in-rails ) showing how to make a nice RSS feed using Builder. The canonical template is something like this: xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "Your Blog Title" xml.description "A blog about software and chocolate" xml.link posts_url for post in @posts xml.item do xml.title post.title xml.description post.content xml.pubDate post.posted_at.to_s(:rfc822) xml.link post_url(post) xml.guid post_url(post) end end end This works fine in

rails 3.1.0 belongs_to ActiveResource no longer working

早过忘川 提交于 2019-12-05 07:22:34
I am upgrading from rails 3.0.7 to 3.1 and am having trouble getting my tests to pass. The problem occurs when I try to use a stubbed active resource object in a factory. #employee.rb class Employee < ActiveResource::Base; end #task.rb class Task < ActiveRecord::Base belongs_to :employee end #factories.rb Factory.define :employee do |e| e.name "name" end Factory.define :task do |t| t.employee { Factory.stub(:employee) } end On the console and in the spec stubbing an employee works. Referencing the stubbed employee object in a new task gives the following error. Factory.create( :task, :employee

How do I precompile assets in rails in development environment?

▼魔方 西西 提交于 2019-12-05 06:06:19
I want to manually precompile some assets in my dev environment (to check the content of the compiled js and css files) from the command line. I am running RAILS_ENV=development bundle exec rake assets:precompile but my js and css are not compiled in the public/assets folder, only the images are. Any idea why that may be happening? Try adding this to your config/environments/production.rb : config.assets.precompile += %w( *.css *.js ) 来源: https://stackoverflow.com/questions/10081832/how-do-i-precompile-assets-in-rails-in-development-environment

How to make AJAX responses work from the Rails side?

£可爱£侵袭症+ 提交于 2019-12-05 05:55:55
问题 The HTML form: <form id="newsletter" method="post" action="/subscribers" data-remote="true"> <label for="email">Enter your email:</label> <input type="text" name="email" class="text" /> <p class="btn"><span>Signup</span></p> </form> Note the data-remote="true" The Controller: class SubscribersController < ApplicationController def create @subscriber = Subscriber.create(:email => params[:email], :ip_address => request.remote_ip ) respond_to do |format| format.js end end end The View

Help to fix strange sqlite3 error - dyld: Library not loaded: /usr/lib/libsqlite3.0.dylib

跟風遠走 提交于 2019-12-05 05:26:36
问题 I am suddenly getting an sqlite3 error: ActionView::Template::Error (dyld: Library not loaded: /usr/lib/libsqlite3.0.dylib Referenced from: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/A/CFNetwork Reason: no suitable image found. Did find: /usr/lib/libsqlite3.0.dylib: mach-o, but wrong architecture /usr/local/lib/libsqlite3.0.dylib: mach-o, but wrong architecture /usr/lib/libsqlite3.0.dylib: mach-o, but wrong architecture I have no idea

How to order by a related model in default scope? — Rails 3.1

喜夏-厌秋 提交于 2019-12-05 05:24:09
How can I write the following default scope: class SimilarMerchant < ActiveRecord::Base # relationships belongs_to :merchant belongs_to :similar_merchant, :foreign_key => 'similar_merchant_id', :class_name => "Merchant" # scopes default_scope order('merchants.is_paid DESC').order('score DESC') end Basically I want to sort by a merchant.is_paid field (which belongs to a related model) Any advice? Marek Příhoda Try this: default_scope joins(:merchant).order('merchants.is_paid DESC, score DESC') And please bear in mind it can be slow, depending on the number of the records here's what you could

Ruby on Rails: why do i get message for javascript and css after rails s?

雨燕双飞 提交于 2019-12-05 04:06:16
rails s=> Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2011-10-11 03:37:03 -0900 Served asset /application.css - 304 Not Modified (0ms) Started GET "/assets/home.css?body=1" for 127.0.0.1 at 2011-10-11 03:37:03 -0900 Served asset /home.css - 304 Not Modified (0ms) Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-10-11 03:37:03 -0900 Served asset /jquery_ujs.js - 304 Not Modified (0ms) Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-10-11 03:37:03 -0900 Served asset /jquery.js - 304 Not Modified (0ms) Started GET "/assets/home.js?body=1" for 127.0.0

Capistrano compile assets error - assets:precompile:nondigest?

北城以北 提交于 2019-12-05 03:01:12
My App seems to be deploying correctly but I'm getting this error: * executing "cd /home/deploy/tomahawk/releases/20120208222225 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile" servers: ["ip_address"] [ip_address] executing command *** [err :: ip_address] /opt/ruby/bin/ruby /opt/ruby/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets I've tried solutions here for trying to compile assets: http://lassebunk.dk/2011/09/03/getting-your-assets-to-work-when-upgrading-to-rails-3-1/ And Here: http://railsmonkey.net/2011/08/deploying-rails-3-1