我有两个型号酒店和地址.关系是:
class Hotel
belongs_to :user
has_one :address
accepts_nested_attributes_for :address
Run Code Online (Sandbox Code Playgroud)
和
class Address
belongs_to :hotel
Run Code Online (Sandbox Code Playgroud)
我需要从一个表单中保存在酒店表和地址表中.
输入表单很简单:
<%= form_for(@hotel) do |f| %>
<%= f.text_field :title %>
......other hotel fields......
<%= f.fields_for :address do |o| %>
<%= o.text_field :country %>
......other address fields......
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
酒店控制器:
class HotelsController < ApplicationController
def new
@hotel = Hotel.new
end
def create
@hotel = current_user.hotels.build(hotel_params)
address = @hotel.address.build
if @hotel.save
flash[:success] = "Hotel created!"
redirect_to @hotel
else
render …Run Code Online (Sandbox Code Playgroud) 我的问题非常简单:如何更改aasm按钮点击的转换?我应该把什么放在我看来?
我有两个按钮:Approve和Reject.我的州看起来像这样:
aasm :column => 'state' do
state :pending, :initial => true
state :approved
state :rejected
event :approve do
transitions :to => :approved, :from => [:pending]
end
event :reject do
transitions :to => :rejected, :from => [:pending]
end
end
Run Code Online (Sandbox Code Playgroud)
更新:我的参数是:
{"utf8"=>"?",
"_method"=>"put",
"authenticity_token"...",
"commit"=>"APP",
"id"=>"65"}.
这就是我从视图中访问操作的方式:
= form_for([:admin, shop], method: :put, data: { confirm: "You sure?" }) do |f|
= f.submit "Approve", :controller => :shops, :action => :approve
Run Code Online (Sandbox Code Playgroud)
我的控制器代码:
def approve
@shop = …Run Code Online (Sandbox Code Playgroud)