ruby-on-rails-3

How to protect my e-mail address from spambots

痴心易碎 提交于 2019-12-22 19:15:09
问题 I was wondering what rails offers to obfuscate e-mail addresses to protect it from crawlers, spambots and mail harvesters, gathering addresses to send spam. May be I used wrong keywords, but wasn’t really able to find a gem. I found a statistic comparing different methods to mask the mail address: http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/ I wrote a snippet that combines the top two methods. The snipped isn’t mature yet, but I like to share it

Rails getting undefined method for existing field in database

萝らか妹 提交于 2019-12-22 18:59:06
问题 So I have a field in the question table, called is_public..I migrated my database, restarted it and now when I get this error everytime I call is_public for a record in the question records. undefined method `is_public' for #<Question:0x7e9aa780> Any ideas to why this is happening ? 回答1: Are you using attr_accessible? If so, add :is_public to the list. 来源: https://stackoverflow.com/questions/5032922/rails-getting-undefined-method-for-existing-field-in-database

how to override gem generator template in Rails app

≯℡__Kan透↙ 提交于 2019-12-22 18:47:37
问题 I know how to override a Rails template in a gem, but how can I override gem generator template in a Rails application e.g.: https://github.com/elabs/pundit/blob/master/lib/generators/pundit/policy/templates/policy.rb or https://github.com/drapergem/draper/blob/master/lib/generators/rails/templates/decorator.rb so that rails g decorator Foo would generate my template, not the gem native one thx 回答1: From Rails guide on generators: In Rails 3.0 and above, generators don't just look in the

Simulating abstract classes in Ruby (Rails)

本小妞迷上赌 提交于 2019-12-22 18:33:11
问题 I want to simulate an abstract class in Ruby on Rails. I.e. I want to raise an exception if someone tries to call Abstract.new , but he should be able to call Child.new (while Child < Abstract ). How to do this? Overwriting both new and initialize does not work. 回答1: Why would you want to do this? The point of abstract/interfaced classes are to hack Strongly typed languages into a dynamic paradigm. If you need your class to fit in the signature, name your methods according to the original

Retrieving sql queries from Active-record queries in Rails 3

情到浓时终转凉″ 提交于 2019-12-22 18:24:40
问题 How do I trace which SQL query did my Activerecord methods generated (eg find, where). 回答1: You can debug ActiveRecord queries from a console. Hit rails console and enter: ActiveRecord::Base.logger = Logger.new(STDOUT) 回答2: I assume you're using Rails 3.0.x, you can do that by configuring your active record. Put this in config/environments/development.rb # Log ActiveRecord ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console Now, every query is explained in console. 回答3:

ruby on rails tutorial - rails 3.0 chapter 11 rspec fails after code listing 11.27

孤人 提交于 2019-12-22 17:59:49
问题 I have run through the book. I run "rspec spec/" after each step. Chapter 11 fails starting listin 11.27 adding app/views/pages/home.html.erb After Listing 11.30. Adding a micropost instance variable to the home action. app/controllers/pages_controller.rb Everything is supposed to be working. It isn't. I am just digging into rails for the very first time. since this was cut and paste code, I did not expect errors. I will be grateful for any help in leaning to debug this. Firure out if I cut

Rails: combining optional params into a query

本小妞迷上赌 提交于 2019-12-22 17:58:02
问题 I have a view with a huge paginated list of records that need filtering. Users can filter by records a few different ways (such as 'saved' records, 'read' records, and 'mark deleted' records) and I'd like for them to be able to combine these filters any possible way. My current, flawed, non-functioning approach. The code below does not produce anything unless all of the params are specified and valid: #view. Set the 'se' filter to true; leave all others as is <%= link_to list_url(:id=>params[

Devise - Redirected to page if account isn't confirmed

陌路散爱 提交于 2019-12-22 17:54:12
问题 I'm trying to redirect the user if their account hasn't been confirmed. So this involves two parts of the code: Redirect the user after they first create the account Redirect them if they try to sign in before confirming the account I need help with the second. The first I was able to do by putting in after_inactive_sign_up_path_for(resource) in my custom RegistrationsController. I've tried to do the same for a SessionsController, but it didn't work. What do I need to over write in order to

How to modify actionmailer email html_part before sending

雨燕双飞 提交于 2019-12-22 17:46:10
问题 I have everything at the point where I'm about to send out the email but I need to modify all links to include Google Analytics attributes. The problem is that if I try and read/write the html_part.body of the email, the entire html string somehow becomes encoded and doesn't display the email properly (i.e. <html> becomes <html> ). I have logged the html_part.body.raw_source in the logger and it shows as proper unencoded HTML, it's only when the email is actually sent does the encoding occur.

how to change default behaviour of rack offline

跟風遠走 提交于 2019-12-22 17:06:32
问题 I am trying to use rack offline in rials to make my webpage available offline. By default rack offline takes all files from the public folder into the cache manifest. In which file should I make changes so that it will take the add the file that I want into the cache manifest. I want to include the file in my views folder. 回答1: You need to add it to your routes.rb file. Here is my routes.rb file with a customized manifest. This will give you the index and the new routes as well as all of the