0
votes

I am trying to set "edit" function for a simple CMS. I can make it to create/delete, but it just won't let me "edit".

here is the error message: SyntaxError in SectionsController#edit app/views/sections/edit.html.erb:42: syntax error, unexpected keyword_ensure, expecting keyword_end Extracted source (around line #42): 40 41

when I checked my edit.html.erb. it seems fine? 'index'}, :class => 'back-link') %>
<div class="sections edit">
  <h2>Update Sections</h2>

  <%= form_for(:two, :url => {:action => 'update', :id => @one.id}) do |f| %>

    <table summary="Section form fields">
      <% @one.each do |f| %>
      <tr>
        <th>Name</th>
        <td><%= f.text_field(:name) %></td>
      </tr>
      <tr>
        <th>Position</th>
        <td><%= f.text_field(:position) %></td>
      </tr>
      <tr>
        <th>Visible</th>
        <td><%= f.text_field(:visible) %></td>
      </tr>
      <tr>
        <th>content_type</th>
        <td><%= f.text_field(:content_type) %></td>
      </tr>
      <tr>
        <th>content</th>
        <td><%= f.text_field(:content) %></td>
      </tr>
      <tr>
        <th>page_id</th>
        <td><%= f.text_field(:page_id) %></td>
      </tr>
    </table>

    <div class="form-buttons">
      <%= submit_tag("Update Section") %>
    </div>

  <% end %>
</div>

Here is the controller:

class SectionsController < ApplicationController
def index
    @one = Section.all
  end

  def show
    @one = Section.find(params[:id])
  end

  def new
    @one = Section.new
  end

  def create
    @one = Section.new(section_params)
    if @one.save
      flash[:notice] = "Section created successfully!"
      redirect_to(:action => 'index')
    else
      render('new')
    end
  end

  def edit
    @one = Section.find(params[:id])
  end

  def update
    @one = Section.find(params[:id])
    if @one.update_attributes(section_params)
      flash[:notice] = "Subject updated successfully!"
      redirect_to(:action => 'show', :id =>@one.id)
    else
      render('edit') 
    end
  end

  def delete
    @one = Section.find(params[:id])
  end

  def destroy
    subject = Section.find(params[:id]).destroy
    flash[:notice] = "Subject deleted successfully!"
    redirect_to(:action => 'index')
  end

  private

    def section_params
      params.require(:two).permit(:id,:name,:position,:visible,:page_id,:content,:content_type)
    end


end

Thanks so much!!

1
You are missing an <% end %> in your form - Pavan
To clarify, your form_for tag needs an end statement, as does the each do loop within the form. You only have one end statement. - MarsAtomic
I had <% end %> just before the </div>. that's the end for form,right? thanks! - ray
@ray you also have one each statement and it requires end too - Mandeep
What about do block? you need an <% end %> for that too - Pavan

1 Answers

0
votes

Thanks @Pavan, @MarsAtomic and @Mandeep ! I found the issue: <% @one.each do |f| %>. I don't really need this line. If I need it, I need a end code for this. In my case, I don't, so I go ahead deleted this line, and it worked now!

thanks again everyone!