2012-03-05 79 views
3

我使用best_in_place寶石編輯餘額:best_in_place寶石編輯貨幣

index.html.erb:

<%= best_in_place bankaccount, :balance, :display_with => :number_to_currency %> 

但編輯後,我得到一個未格式化的數量($改變45〜46顯示爲46)。

我該如何獲得best_in_place作爲$$$顯示新值?

控制器:

respond_to :html, :json 
... 
def update 
    @bankaccount = Bankaccount.find(params[:id]) 
    if @bankaccount.update_attributes(params[:bankaccount]) 
     respond_with @bankaccount 
    else 
     render :json => @bankaccount.errors.full_messages, :status => :unprocessable_entity 
    end 
    # if @bankaccount.update_attributes(params[:bankaccount]) 
    #  redirect_to @bankaccount, :notice => "Successfully updated bankaccount." 
    #  else 
    #  render :action => 'edit' 
    #  end 
    end 
+0

你試過':helper_options => {:unit =>「$」}'? – ScottJShea 2012-03-06 01:02:33

回答

0

最終使用BIP的:display_as =>:mk_bal與mk_bal模型的BankAccount定義爲:

def mk_bal 
    ActionController::Base.helpers.number_to_currency(self.balance, :precision => 2) 
end 
2

該線程已經回答了,但我想接受的答案和它沒有工作。

但是使用lambda一切都很好。順便提一句,Rails 4。

<%= best_in_place @text, :body, :type => :textarea, :display_with => lambda{ |v| markdown(v) }, :html_attrs => { :class => 'edit-text-body' } %> 
+0

試過'= best_in_place資源,:price,activator:'#edit-resource-name',display_with => lambda {| v | number_to_currency(v)}'並沒有工作 – migu 2014-03-26 05:39:53

+0

我已經有這個問題了。你應該看看回購的問題,但它似乎沒有解決方案。 – Sebastialonso 2014-03-26 19:23:20

+0

是的。奇怪的是,它不起作用,因爲':display_with =>:number_to_currency'記錄在Github頁面上。 – migu 2014-03-27 01:20:01