Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8522397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:06:20+00:00 2026-06-11T07:06:20+00:00

My comment controller needs adjust for nesting but I’m getting a few errors. Here’s

  • 0

My comment controller needs adjust for nesting but I’m getting a few errors. Here’s what I’ve been trying:

<% if @commentable == @user %>
  <%= semantic_form_for [@commentable, @comment] do |f| %>
<% else %>
  <%= semantic_form_for [@user, @commentable, @comment] do |f| %>
<% end %>

Which gives this:

/Users/rbirnie/rails/GoodTeacher/app/views/comments/_form.html.erb:3: syntax error, unexpected keyword_else, expecting keyword_end'); else 

Any idea why this isn’t working? Seems simple enough…

Here’s the full view:

<% if @commentable == @user %>
  <%= semantic_form_for [@commentable, @comment] do |f| %>
<% else %>
  <%= semantic_form_for [@user, @commentable, @comment] do |f| %>
<% end %>

  <div class="control-group">
    <%= f.label :subject %>
    <div class="controls"><%= f.text_field :subject %></div>
  </div>
  <div class="control-group">
    <%= f.label :body %>
    <div class="controls"><%= f.text_area :body, rows: 8 %></div>
  </div>
  <div class="form-actions">
    <%= f.submit "Submit", :class => "btn-success" %>
  </div>
<% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:06:22+00:00Added an answer on June 11, 2026 at 7:06 am

    It’s mad because the do bit starts a block, which expects an end to end it. But when the condition is true, it finds an else instead. And note that if the condition was false, it would find an end like it wants – but not the end you want! It would find the end that ends your if statement – not the end that you want to end your block.

    If your semantic_form_for blocks have different contents in each case, use Paritosh’s answer. But if they’re the same code and you want to avoid repeating it, you can pick the arguments conditionally, and then pass them into a single semantic_form_for:

    <% args = (@commentable == @user)? [@commentable, @comment] : [@user, @commentable, @comment] %>
    <%= semantic_form_for(args) do |f|
        Whatever...
    <% end %>
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following View, Controller and Comment.cs code, but I get an error,
Basically i'm trying to build a comment system. The user looks at a photo
I am trying to create a comment that could comment on other comments but
Hi I'm trying to use the CakePHP comments plugin found here http://cakedc.com/downloads/view/cakephp_comments_plugin but the
I'm try something from this comment idea Code Igniter Controller/Model name conflicts find class
As comment to one of the questions here a commenter wrote (emphasis mine): ...
Here's the flow I have... First, jquery posts the new comment to the server:
tl;dr: Jump to the last paragraph Recently I've been trying to use RSpec's request
I'm trying to make a comment system, identical to the stackoverslow's one. There's a
I have a comment controller that uses a form partial to add comments. Now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.