2008年5月1日 星期四

text_field, text_field_tag, link_to, link_to_remote

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000923

text_field(:session, :user, :onchange => "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }")

# => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange = "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }"/>

注意value = @session.user, id = session_user, name = session[user]
還有如何在這使用event像onchange



http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001038
text_field_tag 'payment_amount', '$0.00', :disabled => true

# => <input disabled="disabled" id="payment_amount" name="payment_amount" type="text" value="$0.00" />

id = name = payment_amount



<%= link_to "追蹤",{ :controller => "favorite", :action => "add", :id => @item.id }, :class => "bbt_ch", :title => "追蹤" %>

<%= link_to "", {:action => "push", :id => @item.id}, :confirm => '確定要推薦?', :method => :post, :class => "push" %>

用到些其他options 時, url部份要{} 起來


link_to_remote "Delete this post", :update => "posts", :url => { :action => "destroy", :id => post.id }

link_to_remote "Delete this post", :update => "posts", :url => post_url(@post), :method => :delete, :html => { :class => "destructive" }

<%= link_to_remote "Delete this post", {:url => user_url, :update => "post", :method => :delete}, :class => "sec"%>


url的部份要用url symbol指定, attribute的部份要用html symbol

沒有留言: