ruby-on-rails-3.1

partial form for nested models in rails 3

久未见 提交于 2019-12-11 04:38:39
问题 I have two models pages and author, here is the code of model pages: edit -1 now my models are as follows: class Page < ActiveRecord::Base validates :title, :presence => true belongs_to :author end author model: class Author < ActiveRecord::Base has_many :pages end and my form is as follows: <%= form_for(@page) do |f| %> <% if @page.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@page.errors.count, "error") %> prohibited this post from being saved:</h2> <ul> <% @page.errors

creating a form for deleting uploads that belongs to products

守給你的承諾、 提交于 2019-12-11 04:23:57
问题 I did the multiple uploads with paperclip based on this app https://github.com/websymphony/Rails3-Paperclip-Uploadify and it's working fine, but now I need to build a form where user can delete some of this uploads. I have this form for deleting the uploads for one product <%= form_for @product, :html => { :method => :put }, :html => { :multipart => true } do |f| %> <h3 id="photos_count"><%= pluralize(@product.uploads.size, "Photo")%></h3> <%= f.fields_for :uploads do |photo_fields| %> <% if

javascript not running on heroku with rails 3.1

血红的双手。 提交于 2019-12-11 03:38:22
问题 I've migrated a rails 3.0 app to 3.1 on Heroku. It's running on the cedar stack and everything is fine except that the app's javascript won't run. The application.js file is compiled and looks just as it should. It's accessible by going to myapp.com/assets/application.js. It just doesn't get run! If I run the app locally, the javascript works, so I suspect that there must be some simple configuration issue that I'm missing. Here's my production.rb file: FloridaBirdTrail::Application.configure

i18n search using tire and Globalize3

这一生的挚爱 提交于 2019-12-11 03:36:42
问题 i have a site that uses globalize3 gem (https://github.com/svenfuchs/globalize3) and i'm currently adding the Tire gem to make site search. How do i do to Index a table translations depending on the actual locale? right now the model that gets indexed only does with the default locale. 回答1: You'd have to index all the translations: class Centre < ActiveRecord::Base include Tire::Model::Search include Tire::Model::Callbacks mapping do indexes :title_en, :as => lambda { |post| I18n.locale = :en

Rails3.1 engine: can't get SLIM or HAML to work in test/dummy app

老子叫甜甜 提交于 2019-12-11 03:28:44
问题 I'm developing a Rails 3.1 engine, and to integration test it I want to use SLIM instead of plain ol' ERB. So I tried to simply add s.add_development_dependency "slim" to my .gemspec file, but when renaming my index.html.erb file to index.html.slim , Rails complains: Missing template dummy/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in: * "/Users/josh/Documents/Work/Sientia/iq_menu/full/spec/dummy/app/views" * "/Users/josh/Documents

jQuery-File-Upload content type/extension validation

人盡茶涼 提交于 2019-12-11 03:25:51
问题 I am using jQuery-File-Upload with rails 3, it works very well. But I didn't find anything about how to validate the extension or the content type of the upload file on the client-side. Is there a way to do that? Of cause I will anyway validate it by Paperclip at server-sid, but I think it would be better to validate it once at client-side. 回答1: acceptFileTypes The regular expression for allowed file types, matches against either file type or file name as only browsers with support for the

Activerecord-import & serial column in PostgreSQL

十年热恋 提交于 2019-12-11 03:16:36
问题 I am in the process of upgrading a Rails 2.3.4 project to Rails 3.1.1. The old version used ar-extensions to handle a data import. I pulled out ar-extensions and replaced it with activerecord-import, which I understand has exactly the same interfaces. My code calls looks like this Student.import(columns, values) Both args are valid arrays holding the correct data, but I get a big fat error! The error stack looks like this: NoMethodError (You have a nil object when you didn't expect it! You

Why should I use bundle exec <command> instead of just running the command? [duplicate]

可紊 提交于 2019-12-11 02:45:06
问题 This question already has answers here : Use bundle exec rake or just rake? (3 answers) Closed 5 years ago . Its a well known best practice to use run executables using bundle exec <command> and not just the command. But it seems like nobody could explain why its better to run executebles via bundle exec . So I ask yo why,...? 回答1: If you are using bundle exec instead of just executing command, bundler makes some changes to your environment variable, so all gems listed in your Gemfile can be

Solr Strip html when highlighting with stored html fields

你离开我真会死。 提交于 2019-12-11 02:33:38
问题 Using Solr and Sunspot in rails. I am searching on an html field using a field type like this: <fieldType name="text_html" class="solr.TextField" omitNorms="false"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <charFilter class="solr.HTMLStripCharFilterFactory"/> <filter class="solr.StandardFilterFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.ISOLatin1AccentFilterFactory"/> <filter class="solr.PorterStemFilterFactory"/> </analyzer> </fieldType> I

rails 3.1 multiple currencies

杀马特。学长 韩版系。学妹 提交于 2019-12-11 02:27:30
问题 I have to add more currencies to the app like on this web app http://www.designconnected.com/ as you can see, it converts the price in whatever currency you select and keep it this way. I've been looking for gems that are out of date already, tutorials couldn't find any and in stackoverflow there are a few questions about it but none of them got what I need. if any of you know a better gem, recently released... please let me know. or if there is no gem for it, should I add a currency_id to