ruby-on-rails-3

How to stop/kill server (development) in rubymine

北战南征 提交于 2019-12-30 07:21:11
问题 Newbie here. I created a rails project in rubymine to run the default index.html from public folder I pressed 'shift' + F10 key. This is same as rails server from the terminal. This is what I get: /home/bubble/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/bubble/Desktop/Hard Boiled Bubble/bubbles/script/rails server -b 0.0.0.0 -p 3334 -e development => Booting Mongrel => Rails 3.1.0.rc1 application starting in development on http://0.0.0

Ruby convert IDN domain from Punycode to Unicode

懵懂的女人 提交于 2019-12-30 06:33:26
问题 I'm writing a Rails app that needs to convert an IDN domain name from Punycode into its Unicode equivalent. I tried installing the idn gem that has bindings to GNU LibIDN, but it won't compile the native code. Apparently others have the same issue with Ruby 1.9.x. I also tried the pure Ruby SimpleIDN gem, but I would prefer something native. 回答1: Try the simpleidn gem. It works with Ruby 1.8.7 and 1.9.2. Edit your Gemfile: gem 'simpleidn' then you can enter the command as follows: SimpleIDN

Ruby convert IDN domain from Punycode to Unicode

狂风中的少年 提交于 2019-12-30 06:33:10
问题 I'm writing a Rails app that needs to convert an IDN domain name from Punycode into its Unicode equivalent. I tried installing the idn gem that has bindings to GNU LibIDN, but it won't compile the native code. Apparently others have the same issue with Ruby 1.9.x. I also tried the pure Ruby SimpleIDN gem, but I would prefer something native. 回答1: Try the simpleidn gem. It works with Ruby 1.8.7 and 1.9.2. Edit your Gemfile: gem 'simpleidn' then you can enter the command as follows: SimpleIDN

Allowing users to edit accounts without saving passwords in devise & passing conditions to :reject_if in Ruby

余生颓废 提交于 2019-12-30 05:34:05
问题 I am working on a ROR app, and I'm stuck when it comes to Devise and password confirmation. I'd like for my users to be able to edit their information (name, location, etc) without having to enter and confirm their password (that is unless they decide to change their password, in which case, these fields would be required.) I did a bit of reading when it comes to devise and I noticed that this is a common issue. Unfortunately, I tried all of the solutions posted on the devise GitHub repo, but

How do I create a join action between a group and a user?

被刻印的时光 ゝ 提交于 2019-12-30 05:29:08
问题 user.rb has_many :memberships, :dependent => :destroy has_many :groups, :through => :memberships membership.rb class Membership < ActiveRecord::Base attr_accessible :user_id, :group_id belongs_to :user belongs_to :group validates_uniqueness_of :user_id, :message => "You can only join one group!" end group.rb has_many :memberships, :dependent => :destroy has_many :users, :through => :memberships groups_controller.rb def join @group = Group.find(params[:id]) @m = @group.memberships.build(:user

Ruby map method syntax question [duplicate]

一个人想着一个人 提交于 2019-12-30 05:07:45
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What does map(&:name) mean in Ruby? I was watching railscasts more virtual attributes episode. In that episode, at one point, ryan used a map method syntax which I am not able to understand, Could someone please explain it? tags.map(&:name).join(' ') tags is an object of Tag Model, which has a name attribute. I am able to understand the meaning of this(I think so :)). All the tag object's name attribute are

Custom filtering of parameters in rails 3 using config.filter_parameters

烈酒焚心 提交于 2019-12-30 05:06:07
问题 I'm working on upgrading from Rails 2.3.11 to 3.0.10, and am having trouble converting what is in the ApplicationController 's filter_parameter_logging . I want to filter both certain parameters, and also filter them if they appear in the value of something like a :referrer tag. I can get the regular parameters filtered out in my application.rb config.filter_parameters += [:password, :oauth, ...] But what I'm having trouble with is the block that we also pass in filter_parameter_logging. It

Rails how to change attribute name when rendering json?

折月煮酒 提交于 2019-12-30 04:50:08
问题 In my controller I have: @pakkes = Pakke.where("navn like ?", "%#{params[:q]}%") respond_to do |format| format.html # index.html.erb format.xml { render :xml => @pakkes } format.json { render :json => @pakkes.map(&:attributes) } end How do I change the attribute navn to name when rendering JSON? 回答1: You can do this with a one-line method in Pakke : def as_json(*args) super.tap { |hash| hash["name"] = hash.delete "navn" } end Calling super will generate json hash as usual, then before it's

How to render a RAILS partial with local variable f in new.js.erb?

半世苍凉 提交于 2019-12-30 04:45:10
问题 There is a way to render a erb page in js.erb like this with :remote => true in rails: $('#invoice_against_lease').html('$("<%= j render(:file => 'invoice/new.html.erb') %>")'); We have a partial _customer_quote_record like this: <%= f.input :quote_id, :label => 'Quote#:', :collection => quotes_for_invoice(@customer), :include_blank => true %> <%= f.hidden_field :_destroy %> The partial is rendered in html.erb as this, with passing local variable builder: <%= f.simple_fields_for :invoice

How to add callback after registration with Rails3 and Devise

萝らか妹 提交于 2019-12-30 04:25:09
问题 How to add a callback to create an account for the registered user. Devise files (registrations_controller.rb) are under controllers/devise My user model has has_many :accounts relationship (and the account model has belongs_to :user) First I don't know where to add the callback (what file?) Then, how to automatically create a new account with the right user_id of the registered user? Thanks in advance. 回答1: You can override devise's registration controller, add callback to create account