ruby-on-rails-3.1

How to view navigation with infinit sub entries?

倖福魔咒の 提交于 2019-12-25 02:22:09
问题 Ive got a simple Model called Category. The model is has three fields : name:string , parent_id:integer and of cause an id ! The parent_id is an self referential association: has_many :children, :class_name => 'Category', :foreign_key => 'parent_id' belongs_to :parent, :class_name => 'Category', :foreign_key => 'parent_id' So every Category can have subcategories and on and on and on,... This isnt a problem at the database but when it comes to the view Im getting confused! I dont get how I

Rails how to create chart data for each month between 2 dates?

不打扰是莪最后的温柔 提交于 2019-12-25 02:18:50
问题 In my model I have: def self.chart_data(start, slut) if start.nil? start = 2.weeks.ago end if slut.nil? slut = Date.today end range = start.to_date..(slut.to_date + 1.day) if start.to_date.beginning_of_month.to_s != slut.to_date.beginning_of_month.to_s kliks = count( :group => 'date(month)', :conditions => { :created_at => range } ) # CREATE JSON DATA FOR EACH MONTH - PROBLEM HERE (range).map(&:beginning_of_month).uniq.map(&:to_s).each do |month| { created_at: month, clicks: kliks[month] || 0

AuthLogic UserSessions Controller Returning Nil [closed]

拥有回忆 提交于 2019-12-25 02:18:45
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I've set up a new Rails app and am using Authlogic for authentication. I can happily CRUD users but there seems to be an issue with User Sessions. Error

Unitialized constant in model

青春壹個敷衍的年華 提交于 2019-12-25 02:08:09
问题 I have a very simple model using Mongoid. I've added the use of Redcarpet to parse the MD and store it. However during update_attributes it is throwing an exception. Running the model and running the update through rails c works fine. class Post include Mongoid::Document field :contents_markdown field :contents key :title before_create :markdown before_save :markdown protected def markdown if self.contents_markdown self.contents = Redcarpet.new(self.contents_markdown).to_html.html_safe end

Why do I get error “undefined method `write_inheritable_attribute'” in my migration?

情到浓时终转凉″ 提交于 2019-12-24 20:39:39
问题 I attempted to generate a migration like: rails generate migration RemovefromGenotypes box:integer well:string but then I get this error: /usr/share/rails-ruby1.8/railties/lib/rails_generator/options.rb:32:in `default_options': undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError) from /usr/share/rails-ruby1.8/railties/lib/rails_generator/base.rb:90:in `<class:Base>' from /usr/share/rails-ruby1.8/railties/lib/rails_generator/base.rb:85:in `<module

ActiveAdmin: Sort by association (belongs_to)

自作多情 提交于 2019-12-24 20:37:51
问题 I have an index admin view where I'm displaying an associated model City . I'd like to be able to sort by city name, but when I click the column header to sort I get the following error: ActiveRecord::StatementInvalid in Admin/deals#index SQLite3::SQLException: no such column: cities.name: SELECT "deals".* FROM "deals" ORDER BY cities.name desc LIMIT 30 OFFSET 0 Index view ActiveAdmin.register Deal do index do column :id column :city end ... end Model class Deal < ActiveRecord::Base belongs

how to create select box from a given list in rails?

て烟熏妆下的殇ゞ 提交于 2019-12-24 20:15:07
问题 I am passing a list from my controller @distinct_grade_list = Student.uniq.pluck(:grade) which creates the distinct list of grades from model Student now in my view page , how can i display it as select box I am using <%= collection_select(A, @distinct_grade_list, B, C, D) %> now what do i have to keep at A,B,C,D 回答1: collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) public why not read the api document and sample? sample usage: class

Rails 3.1, can't make link_to image_path?

核能气质少年 提交于 2019-12-24 19:15:13
问题 I want to make a fairly straightforward image link that uses an image from my assets. Getting weird errors. First I tried: <%= link_to assets_path "town.png", 'index' %> and got the error Started GET "/" for 127.0.0.1 at Wed Nov 30 17:27:10 -0500 2011 Processing by PagesController#intro as HTML Rendered pages/intro.html.erb within layouts/application (114.9ms) Completed 500 Internal Server Error in 124ms ActionView::Template::Error (undefined method `assets_path' for #<#<Class:0x10fdc4898>

Rails 3.1 CoffeeScript/JQuery - How to change the source of an image in a div?

有些话、适合烂在心里 提交于 2019-12-24 12:51:44
问题 I would like to change the image of a link with jquery. This is what I tried : In my Haml file : .selected = link_to image_tag('/assets/unselected.png'), {:controller => Posts, :action => "update", :selected => true}, :id => "selected_post", :remote => true, :method => :put After some stuff in my posts_controller, here is the update.js.coffee where I tried to change the image of the link with a new one called selected.png : $("selected_post").attr 'src', '/assets/selected.png' I does not work

Image and print_media_type for pdfkit are not working on rails 4.0.2

走远了吗. 提交于 2019-12-24 11:25:06
问题 I have created a pdf using pdfkit.Pdf is created. But the image is not displaying on my pdf and the print_media_type is also not working. I am using rails 4.0.2 and ruby 2.0.0. can anyone please help me to solve this problem? I am attaching details here. Thank you. gem file: gem 'pdfkit','0.5.2' gem 'wkhtmltopdf-binary','0.9.9.1' gem 'wkhtmltopdf-heroku','1.0.0' application.css : @media print { body { text-align: justify; font-size:566px; background-color: red; } } application.rb: require