我搭建了一個授權(user_id,code,otherparam1,...),並且我想將一個custom_create方法添加到authorizations_controller,它只需要一個代碼,該方法生成其他參數。我需要這個方法使用JSON工作或其他方法,比如User.newcustom(代碼)Ruby自定義創建方法
def newcustom
case request.method
when :post #post
code = params[:code]
if(code and code != '')
...
respond_to do |format|
if @authorization.save
format.html { redirect_to @authorizations, notice: 'Authorization was successfully created.' }
format.json { render json: @authorizations, status: :created, location: @authorization }
else
format.html { render action: "new" }
format.json { render json: @authorization.errors, status: :unprocessable_entity }
end
end
else #get
respond_to do |format|
format.html
end
end
叫這裏是我的newcustom.html.erb
<%= form_tag(newcustom_authorizations_path, :method => :post) do %>
<div class="field">
<%= text_field_tag :code %>
</div>
<div class="actions">
<%= submit_tag('Get tokens') %>
</div>
<% end %>
但它不通過JSON工作, 表格。並調用newcustom(:code => code)方法會引發太多參數(1代表0)。任何想法 ?
你在哪裏叫newcustom? –
這不是PHP,老兄!您需要RESTful操作。 – MikDiet
向我們顯示錯誤消息/堆棧跟蹤和錯誤消息中引用的代碼。 –