ruby-on-rails-3.1

ActionView::Template:Error(undefined method 'first_name' for nil:NilClass)

白昼怎懂夜的黑 提交于 2020-01-07 00:36:42
问题 My app seems to randomly be throwing an error when users are trying to load grid data into the form: ActionView::Template::Error (undefined method `first_name' for nil:NilClass): 3: t = @conts 4: xml.tag!("row",{ "id" => t.id }) do 5: 6: xml.tag!("cell", t.first_name) 7: xml.tag!("cell", t.last_name) 8: xml.tag!("cell", t.email) 9: xml.tag!("cell", t.phone_1) And following is the controller file def compdata @conts = Continfo.find_by_id(params[:id]) end Correspondence compdata RXML file xml

Rails 3.1, internalization of values from a habtm relationship?

有些话、适合烂在心里 提交于 2020-01-06 20:06:46
问题 I got a Event model that HABTM Categories. The relationship works fine and I can insert/retrieve values from Categories with no problem. My questions is, is there a way to interzationalize(I18n) the values of this categories. Category Model class Category < ActiveRecord::Base has_and_belongs_to_many :events end Event Model class Event < ActiveRecord::Base .... has_and_belongs_to_many :categories .... _form.html.haml (for events) - Category.all.each do |category| .field = check_box_tag

Rails 3.1, internalization of values from a habtm relationship?

[亡魂溺海] 提交于 2020-01-06 20:06:39
问题 I got a Event model that HABTM Categories. The relationship works fine and I can insert/retrieve values from Categories with no problem. My questions is, is there a way to interzationalize(I18n) the values of this categories. Category Model class Category < ActiveRecord::Base has_and_belongs_to_many :events end Event Model class Event < ActiveRecord::Base .... has_and_belongs_to_many :categories .... _form.html.haml (for events) - Category.all.each do |category| .field = check_box_tag

Rspec error when I run my rspec test of my controller

独自空忆成欢 提交于 2020-01-06 14:10:57
问题 I am developing a Rails v2.3 application. When I run the rspec test by execute command: rspec spec/controllers/my_controller_spec.rb I got the error message which is showing below: /.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded': (RuntimeError) ******************************************************************************** You are running rspec-2, but it seems as though rspec-1 has been loaded as well. This is likely

How to Call a View Helper Method in JavaScript using Rails 3.1

故事扮演 提交于 2020-01-06 09:56:43
问题 I'm working on a simple app that needs to render a time. But the time must be formatted the way time_ago_in_words helper does. I'm getting the time data from a JSON object. Is it possible to trigger a view helper (time_ago_in_words) inside a JavaScript file? I'm using Rails 3.1 Thanks. 回答1: You can't do it from inside a javascript function. Ideally you would want a JSON equivalent to XML Builder where you could call the view helper methods from inside a .builder partial. This gem provides

Rails 3.1 ckeditor: Adding fontsize in toolbar?

筅森魡賤 提交于 2020-01-06 09:32:47
问题 I have ckeditor in my rails 3.1 app but I am not able to add fontsize and font dropdowns to my toolbar. My edit view code: <%= javascript_include_tag "ckeditor/ckeditor.js" %> ... <%= form_for @page, :html => { :class => 'edit_page', :id => "page_form" } do |page| %> ... <%= page.cktext_area :content, {:height => "350px", :width => "920px"}%> ... <% end %> I am able to adjust the height and width but not add any other parameters? 回答1: Could be late but in rails 3.1 app you can go to /vendor

Rails 3.1 ckeditor: Adding fontsize in toolbar?

廉价感情. 提交于 2020-01-06 09:31:14
问题 I have ckeditor in my rails 3.1 app but I am not able to add fontsize and font dropdowns to my toolbar. My edit view code: <%= javascript_include_tag "ckeditor/ckeditor.js" %> ... <%= form_for @page, :html => { :class => 'edit_page', :id => "page_form" } do |page| %> ... <%= page.cktext_area :content, {:height => "350px", :width => "920px"}%> ... <% end %> I am able to adjust the height and width but not add any other parameters? 回答1: Could be late but in rails 3.1 app you can go to /vendor

Add Bootstrap-Image-Gallery to a Rails project

白昼怎懂夜的黑 提交于 2020-01-06 07:34:20
问题 I found this nice Image gallery addon for Bootstrap but I am not sure how to integrate it on my rails project. https://github.com/blueimp/Bootstrap-Image-Gallery I figured I could use Rails (3.1) vendor's folder. So that's what I did. I cloned those files in the vendor/assets folder: git clone https://github.com/blueimp/Bootstrap-Image-Gallery.git Ok now it's there, how do I use it? How do I load these resources in my application? my current application.js: //= require jquery //= require

How can I see if the string is numeric?

落花浮王杯 提交于 2020-01-06 03:54:30
问题 I have the string "08" and I like to know if this string is numeric. How can I do it in Rails 3.1? 回答1: Another way to do this is to leave it up to ruby to determine it: begin Float(string) # String is numeric rescue ArgumentError, TypeError # String is not numeric end 回答2: You can use a regular expression: str = "08" if str =~ /^-?(\d+(\.\d+)?|\.\d+)$/ # string is numeric else # string is not end 回答3: If you are wanting to validate user input it would be just as simple to only allow them to

JRuby 1.6.3 and Rails 3.1rc5 and activerecord-3.1.0.rc5 and destroy_all

。_饼干妹妹 提交于 2020-01-06 03:03:22
问题 I am able to create able to run my migrations from JRuby 1.6.3 and Rails 3.1rc5 and in a console session create a simple Role object like this: jruby-1.6.3 :001 > role = Role.new(:name => "Admin") (1.0ms) SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' => #<Role id: nil, name: "Admin", created_at: nil, updated_at: nil> All is good but when I run Role.destroy_all I get the following stack trace: jruby-1.6.3 :003 > Role.destroy_all ArgumentError: wrong