Cannot update my store profile in ruby on rails

46 Views Asked by At

Those are the edit and update actions :

def edit
    @store_to_edit = StorePost.find(params[:id])

  end

  def update 
    @store_to_edit = StorePost.find(params[:id])
    if @store_to_edit.update(store_params)
      flash[:success] = 'store updated'
      redirect_to @store_to_edit
    else
      render 'edit', status: :unprocessable_entity
    end
  end

store parameters method :

private
  def store_params
    params.require(:store).permit(:name, :country, :state, :city)
  end

Those are the routes :

post  '/store_posts/:id/edit', to: 'store_posts#update'
resources :store_posts, only: [:new, :create, :show, :edit, :update]

This is the form for the edit page e.g. /store_posts/4/edit:

<%= form_with(model: @store_to_edit) do |f| %>
    <div class='field'>
            <%= f.text_area :name, placeholder: 'name...' %>
    </div>
    <div class='field'>
            <%= f.text_area :country, placeholder: 'country...' %>
    </div>
    <div class='field'>
            <%= f.text_area :state, placeholder: 'state...' %>
    </div>
    <div class='field'>
            <%= f.text_area :city, placeholder: 'city...' %>
    </div>
    
    <%= f.submit 'save changes', class: 'btn btn-primary' %>
<% end %>

but when I press 'save changes' it just redirect me to the same page and it doesn't update

Edit

This is the error it gives me :

Completed 400 Bad Request in 12ms (ActiveRecord: 0.3ms | Allocations: 1198)

ActionController::ParameterMissing (param is missing or the value is empty: store):

app/controllers/store_posts_controller.rb:122:in `store_params'
app/controllers/store_posts_controller.rb:43:in `update'
0

There are 0 best solutions below