Tag: 简单forms

Rails Simpleform与非模型输入

我有一个使用simpleform的普通表单。 现在我想添加一个在模型中没有任何相应字段的输入,它将由控制器处理。 我试过了 <– should just send "attr" as post data 但这会Method not found: attr_not_in_obj一个Method not found: attr_not_in_obj的Method not found: attr_not_in_obj错误。 我显然可以使用标准的rails帮助器,但是我会错过输入周围的所有simpleform HTML,并且复制看起来不太合适。 简而言之:我正在寻找类似于简单forms的rails标签助手的东西,而不需要任何与模型的连接。 如何添加与模型属性不对应的输入?

控制器无法检测到Ajax请求

我正在使用simple_form gem并生成我指定remote:true选项的表单,如下所示: 因此,表单的输出html是以下片段: … 在我检查时,使用标准的form_for帮助程序是在使用remote:true选项时将data-remote =’true’添加到表单中。 从生成的html中可以看出,当我使用simple_form gem时,也有这样的属性。 所以,在我的控制器中我有: def create @webinar = Webinar.new(params[:webinar]) respond_to do |format| if @webinar.save format.html { redirect_to @webinar, notice: ‘Webinar was successfully created.’ } format.js format.json { render json: @webinar, status: :created, location: @webinar } else format.html { render action: “new” } format.json { render json: @webinar.errors, status: :unprocessable_entity } […]

通过与其他属性相关联来创建has_many的Rails表单?

如何为has_many :through生成表单字段has_many :through具有其他属性的关联? has_many :through关系有一个名为weight的附加列。 这是连接表的迁移文件: create_table :users_widgets do |t| t.integer :user_id t.integer :widget_id t.integer :weight t.timestamps end 模型看起来像这样: User has_many :widgets, :through => :users_widgets, :class_name => ‘Widget’, :source => :widget has_many :users_widgets accepts_nested_attributes_for :widgets # not sure if this is necessary Widget has_many :users, :through => :users_widgets, :class_name => ‘User’, :source => :user has_many […]