ruby-on-rails-3

Rails 3 not loading HAML handler

懵懂的女人 提交于 2020-01-03 10:22:04
问题 I'm having some problems with Rails 3 and HAML in my application: for some reason Rails appears not to be loading the handler for dealing with haml files. Every action gives an error message similar to this one: Template is missing Missing template contact_search/index with {:formats=>[:html], :handlers=>[:rjs, :rhtml, :rxml, :builder, :erb], :locale=>[:en, :en]} in view paths "/var/www/osphonebook/app/views", "/var/www/osphonebook/vendor/bundle/ruby/1.8/gems/devise-1.3.4/app/views" Look at

HAML: Indenting if/else statements with common content

别说谁变了你拦得住时间么 提交于 2020-01-03 09:58:17
问题 I have the following in my view: - if (condition) %div.truecondition (Ten lines of content) - else %div.falsecondition (Ten lines of the same content) I'd like to factor out the ten lines of content to go below the if/else statement...but if I do that, indentation means the content won't be nested inside the div specified in the if/else. I'm sure this is a common problem, I'm just wondering what the solution is. So...how do I factor out that ten lines while keeping the content nested in the

Nested table formatting with simple_form, nested_form and twitter-bootstrap

旧巷老猫 提交于 2020-01-03 09:12:11
问题 Update: I updated this after doing some digging and realizing that this might be twitter-bootstrap causing the problem. Here is a rough version of my nested form: <%= simple_nested_form_for @user, :html => { :class => 'form-horizontal' } do |f| %> <fieldset> <%= f.input :email %> <%= f.input :name_first %> <%= f.input :name_last %> <table class="table table-striped"> <thead> <tr> <th>Active</th> <th>Company</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <%= f.simple_fields_for

ActiveRecord, find by polymorphic attribute

扶醉桌前 提交于 2020-01-03 09:11:51
问题 Having this: class Event < ActiveRecord::Base belongs_to :historizable, :polymorphic => true end user = User.create! I can: Event.create!(:historizable => user) But I can't: Event.where(:historizable => user) # Mysql2::Error: Unknown column 'events.historizable' in 'where clause' I have to do this instead: Event.where(:historizable_id => user.id, :historizable_type => user.class.name) Update Code that reproduces the issue: https://gist.github.com/fguillen/4732177#file-polymorphic_where_test

ActiveRecord, find by polymorphic attribute

故事扮演 提交于 2020-01-03 09:11:06
问题 Having this: class Event < ActiveRecord::Base belongs_to :historizable, :polymorphic => true end user = User.create! I can: Event.create!(:historizable => user) But I can't: Event.where(:historizable => user) # Mysql2::Error: Unknown column 'events.historizable' in 'where clause' I have to do this instead: Event.where(:historizable_id => user.id, :historizable_type => user.class.name) Update Code that reproduces the issue: https://gist.github.com/fguillen/4732177#file-polymorphic_where_test

How do I use the `--helper` flag in a rails 3 controller generator?

半城伤御伤魂 提交于 2020-01-03 08:48:12
问题 The documentation from rails generate controller says: [--helper] # Indicates when to generate helper # Default: true Now, it doesn't specify how to indicate a value. So, since the default is true, that means that excluding it won't indicate false, because… true is the default. So it must either be --helper=false or --helper false , but I tried both, and they both resulted in error false [not found] The good news is that it did not generate a helper, because it was confused, so I still got

Can I drop '?' in form triggered GET request?

二次信任 提交于 2020-01-03 08:37:09
问题 I want to replace a simple link with a button for styling purposes. Using button_to in place of link_to seems the path of least resistance, and I'm at least aspiring to keep things RESTful, which means a GET request in this case. When I replace: link_to "my_page", my_page_path with: button_to "my_page", my_path_path, :method => :get ... there's a '?' appended to the end of the URL. It's a small matter, of course. But is there a simple way to drop the '?', since I have no query string

Manually set column name in rails model

让人想犯罪 __ 提交于 2020-01-03 08:36:12
问题 I'm building a rails app around several existing databases, the column names used in the existing databases do not work well at all with the rails association conventions. Is there a way to set column name aliases in a model similar to the way you can class User < Activerecord::Base self.set_table_name "users" end Could I set column name aliases when the existing db columns will not work with default rails association naming conventions? 回答1: In your model, just setup alias for attributes

Rails 3: how to render text file in-line?

♀尐吖头ヾ 提交于 2020-01-03 08:26:30
问题 All. A Rails n00b here... I'm writing an application that reports the status of a transaction. Some of the content in the rendered HTML comes from instance variables initialized in the controller, while other content comes from text files (e.g., log files) that I want to render in the HTML using <pre> tags. What is the "Rails Way" to do this? Thank you for your time... 回答1: <pre> <%= render :file => '/tmp/test.log' %> </pre> 回答2: Here you go: http://edgeguides.rubyonrails.org/layouts_and

How can this destroy action be tested with RSpec?

强颜欢笑 提交于 2020-01-03 08:07:46
问题 In my Rails app, if a user wants to delete his own account he will first have to enter his password in my terminate view: <%= form_for @user, :method => :delete do |f| %> <%= f.label :password %><br/> <%= f.password_field :password %> <%= f.submit %> <% end %> This is my UsersController : def terminate @user = User.find(params[:id]) @title = "Terminate your account" end def destroy if @user.authenticate(params[:user][:password]) @user.destroy flash[:success] = "Your account was terminated."