samedi 16 avril 2016

rails update set of record in single model and form

iam new to rails, i have model(welcome) and i want to update the model with single form where the form has duplicate fields . only second field updates the model ..

routes

  get 'welcome/index'
  get 'welcome/new'
  post 'welcome/create'
  root 'welcome#index'
welcomecontroller
class WelcomeController < ApplicationController
  def index
  end
  def new
    @article = Welcome.new
  end
  def create
    @article = Welcome.new(user_params)
    if @article.save
      redirect_to welcome_new_path
    else
      render 'new'
    end
  end
  
  private
  
  def user_params
    params.require(:welcome).permit(:name , :descrip  )
  end
end
welcomeindex view
<%= form_for@ article, url: welcome_create_path do |f | %>
  <%= f.text_field: name %>
  <%= f.text_field: descrip %>
  <%= f.text_field: name %>
  <%= f.text_field: descrip %>
  <%= f.submit "Create" %>
<% end %>
thanks

Aucun commentaire:

Enregistrer un commentaire