我沒有錯誤,但當我點擊「確定」(提交按鈕)什麼都沒有發生,我的數據庫根本沒有改變, 即時通訊按我的應用程序,如我按下一個按鈕,然後所有進一步的頁面已經被加載,並且我使用ajax和jquery在它們之間導航,並且在這些頁面之一中實現我的表單。這可能是因爲這個?當我在 「OK」 點擊(提交按鈕)它真的不控制檯上的反應:S我不能保存提交數據庫
我的窗體上的部分: _impediments_risks.html.erb
<div class="item-list">
<%@solution = Solution.new(params[:solution])%>
<% for i in (0..session[:project_impediments].size-1) %>
<div class="item">
<% impediment = session[:project_impediments][i][1] %>
<div class="title">
<span class="indicator"><%= impediment.priority.name %></span>
<div class="description"><%= impediment.subject %></div>
</div>
<div class="content">
<span class="title"><%= I18n.t 'text.solution' %></span>
<ul>
<% sol = ApplicationHelper.apply_filter(ApplicationHelper.Hash_DB(Solution.where('user_id IS NULL or user_id=?',session[:user])), ApplicationHelper.stem_phrase(impediment.subject.downcase)) %>
<% sol.each do |s| %>
<li><%= s %></li>
<% end %>
<li><b>NEW SOLUTION</b></li>
<li>
<%= form_for(@solution) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :text %>
<%= f.text_field :text %>
<%= f.label :keywords %>
<%= f.text_field :keywords %>
<%= f.submit "Ok", class: "btn btn-large btn-primary" %>
<% end %>
</li>
</ul>
</div>
</div>
<% end %>
</div>
我CONTROLER solutions_controller.rb
class SolutionsController < ApplicationController
def new
@solution = Solution.new
end
def create
@solution = Solution.new(solution_params)
if @solution.save
#flash.now[:success] = "New Solution created!"
else
#Something
end
end
private
def solution_params
params.require(:solution).permit(:text, :keywords)
end
end
我的模型: solution.rb
class Solution < ActiveRecord::Base
attr_accessible :text, :keywords, :contar , :user_id
before_save { |solution| solution.keywords = solution.keywords.downcase }
default_scope -> { order('contar DESC') }
validates :text, presence: true, uniqueness: { case_sensitive: false }
VALID_KEYS_REGEX = /\A([a-zA-Z]{3,})+(&|\|[a-zA-Z]{3,}+)*\z/i
validates :keywords, presence:true, format: { with: VALID_KEYS_REGEX }
end
發表你的'提交'form'時登錄information'。 – Pavan
也嘗試給這個'<%= form_for(@solution,:url => {:action =>「create」,:controller =>'solutions'})do | f | %>' – Pavan
如果你使用強參數,你不應該有attr_accessible 另外,如果你試圖消滅關鍵字,你應該有'self.keywords = keywords.downcase' –