ruby-on-rails-3.2

Rails render partial with :collection

若如初见. 提交于 2019-12-04 01:01:35
This is so simple it shouldnt be an issue but I dont understand whats going on here. I have the following code class DashboardController < ApplicationController def bookings @bookings = Booking.all end end /views/dashboard/bookings.html.erb <%= render 'booking', :collection => @bookings %> /views/dashboard/_booking.html.erb <%= booking.booking_time %> I get the following error undefined method `booking_time' for nil:NilClass However if I do this in /views/dashboard/_bookings.html.erb <% @bookings.each do |booking| %> <%= render 'booking', :booking => booking %> <% end %> I get (correct) 2012

rake test and error : log writing failed. “\\xE2” from ASCII-8BIT to UTF-8

与世无争的帅哥 提交于 2019-12-03 23:40:50
When I run rake test , I get error line every time. log writing failed. "\xE2" from ASCII-8BIT to UTF-8 Please guide on this. How to remove this error. You probably have somewhere in your code trying to output string whose encoding is wrong or has some weird characters and the encoding doesn't work. Correct way would be to find the string that results in problems and find out why its in wrong encoding. See encoding and force_encoding in string api ( http://ruby-doc.org/core-2.2.0/String.html ). If you just want to be able to print that line in the log and avoid the error you can do the

Rails dev environment not updating html/css/assets even after restarting server

做~自己de王妃 提交于 2019-12-03 23:39:48
I've been developing a site in rails, everything going relatively smooth. Suddenly my changes to the views and assets no longer show up. I change a stylesheet or some html and reload my browser at http://0.0.0.0:3000 and nothing changes. So I restart WEBrick and still nothing's changed. This is even the case if I change an image entirely. The only way to get the new changes is to precompile the assets: C:\Users\me\website>rake assets:precompile C:/Ruby193/bin/ruby.exe C:/Ruby193/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets Why is it showing production as the RAILS

How to iterate through JSON hash with coffeescript

倾然丶 夕夏残阳落幕 提交于 2019-12-03 22:52:51
I'm new to Coffeescript and I'm having issues resolving an issue. I have a JSON object that is currently stored in a variable. How do I iterate through the keys in the JSON object to display the key name and values associated with it? if client result = JSON.parse client $.each result, (k, v) -> alert k + " is " + v Any help would be appreciated. for key, value of result console.log "#{key} and #{value}" more in the docs#loops result = JSON.parse client for c in result console.log(c.key +"-"+ c.value) it's work! 来源: https://stackoverflow.com/questions/12941915/how-to-iterate-through-json-hash

error precompiling assets when moving to production

帅比萌擦擦* 提交于 2019-12-03 21:43:57
I am trying to move my project to production, trying to RAILS_ENV=production bundle exec rake assets:precompile gives me an error, without specifying in which file it is. rake aborted! Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}" (sass):89 /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1207:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1137:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:42:in `parse' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib

Rails: Turn off error display

雨燕双飞 提交于 2019-12-03 20:25:24
问题 When I access a post that doesn't exist in my Rails project via the URL /posts/13 , the browser shows a verbose error: ActiveRecord::RecordNotFound in PostsController#show Couldn't find Post with ID=13 Rails.root: ... ... Request Parameters: {"id"=>"13"} ... Is there a way to turn this detailed error display off? 回答1: Try this: run a server in production $ rails s -e production remove ActionDispatch::DebugExceptions middleware config.middleware.delete(ActionDispatch::DebugExceptions) set

Print valid, non-escaped JSON in a view with Rails

喜你入骨 提交于 2019-12-03 19:52:10
问题 I've tried everything. Every combination of the helpers raw , html_safe to_json including some attempts with ::JSON.encode and CGI.unescape . The issue is that regardless of what I do, I can't print well-formed JSON in a view. It's always HTML escaped. Here's the code in my view: var campaignData<%= "=" + (raw @campaign.to_json) if @campaign %>; In my case, it's always the quotes that are escaped as ". I would just do a gsub on the quotes, but that is a terrible solution to what IMO ought to

How to handle non-root URLs in a singlepage app?

风流意气都作罢 提交于 2019-12-03 19:36:52
问题 I try to make a single page app with Rails 3.2 and Backbone.js with pushState option but faced with something that I do not understand. If I load the root URL of the app (/), everything goes right: Rails return an HTML-layout with JS which bootstraps Backbone which makes some XHRs for JSON-entities and renders the content. But if I start using app from non-root URL (e.g. by manually typing it in the browser's address bar) then Rails will try to handle this request using theirs routing rules

Is it possible to skip the asset precompile step for a single git push on Heroku?

被刻印的时光 ゝ 提交于 2019-12-03 19:05:22
问题 Every time I deploy my Rails 3.2 project to Heroku, rake assets:precompile is run: $ git push heroku master ... ----> Preparing app for Rails asset pipeline Running: rake assets:precompile Asset precompilation completed (189.17s) ... Sometimes I want to make a push that I know does not change any assets, such as a quick hotfix to a controller. Is it possible to skip the asset:precompile step for a single git push to Heroku? Thanks. 回答1: Sure! You'll need to create a manifest.yml in your_app

Custom text for rails form_for label

余生颓废 提交于 2019-12-03 18:32:30
问题 I want to display a label in form_for : <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> This generates the label "Name", but I want it to be "Your Name". How can I change it? 回答1: The second parameter to label helper will allow you to set custom text. <%= f.label :name, 'Your Name' %> Use Ruby on Rails Documentation to look up helper methods. 回答2: You can specify custom label text via i18n. In config/locales/en.yml , and assuming your user model is named user ,