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

  • SEARCH
  • Home
  • 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 8023171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:29:39+00:00 2026-06-04T22:29:39+00:00

I want to modify the action (submit) for a form_for helper <%= form_for(@rating, :as

  • 0

I want to modify the action (submit) for a form_for helper

<%= form_for(@rating, :as => :post, :url => demo_create_rating_path(@rating)) do |f| %>
  <div class="field">
    <%= f.label :value %><br />
    <%= f.select :value, %w(1 2 3 4 5) %>
  </div>
    <%= f.hidden_field :article_id, :value => @article.id%>
    <%= f.hidden_field :user_id, :value => current_user.id %>
  <div class="field">
    <%= f.label :description %><br />
    <%= f.text_area :description, size: "100x5" %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

This is my View and it does not work.

All I want is, that I can redirekt the Action after submit button but then a get this error:

ActionController::RoutingError (No route matches {:controller=>"demo_ratings", :action=>"create", :article_id=>#<Rating id: nil, value: nil, description: nil, article_id: nil, user_id: nil, created_at: nil, updated_at: nil>}):
  app/views/demo_ratings/_form.html.erb:1:in `_app_views_demo_ratings__form_html_erb__1912848844925280312_70155649546120'
  app/views/demo_ratings/new.html.erb:13:in `_app_views_demo_ratings_new_html_erb__27525029454473720_70155632487040'

What am I doing wrong?

UPDATE

All my funktion that are need by form_for helper:

def new
    @rating = Rating.new
    @article = Article.find(params[:article_id])
  end

  def edit
    @rating = Rating.find(params[:id])
    @article = Article.find(params[:article_id])
  end

  def create
    @rating = Rating.new(params[:rating])
    if @rating.save
      @article= Article.find(params[:article_id])
      puts @article.name
      puts @rating.id
      @rating.article = @article
      puts @rating.article.name
      redirect_to demo_rating_path(@rating, :article_id => @article.id), notice: 'Rating was successfully created.'
    else
      render action: "new"
    end
  end

  def update
    @rating = Rating.find(params[:id])
    if @rating.update_attributes(params[:rating])
      @article = @rating.article
      redirect_to demo_rating_path(@rating), notice: 'Rating was successfully updated.'
    else
      render action: "edit"
    end
  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-04T22:29:40+00:00Added an answer on June 4, 2026 at 10:29 pm

    Try this:

    <%= form_for(@rating, :as => :post, :url => demo_create_rating_path) do |f| %>
    

    The @rating in the url is providing a nil object id, and you don’t have an id yet.

    If you want to share the form between create and update, then use the following:

    <% form_for(@rating, :as => :post) do |f| %>
    

    For reference, review the output of a rails generated scaffold’s _form.html.erb.

    In your controller, your are saving the new/ updated record before your processing. The statement if @rating.save should come after @rating.article = @article.

      def create
        @rating = Rating.new(params[:post])
        @article= Article.find(params[:article_id])
        @rating.article_id = @article.id
        if @rating.save
          redirect_to demo_rating_path(@rating, :article_id => @article.id), notice: 'Rating was successfully created.'
        else
          render action: "new"
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to modify a view from Action Helper in Zend Framework in preDispatch()
Is there any way to modify or set-header of request inside action class? I
I want to modify something in Settings.secure database, just as the android Settings app
I want to modify (Remove all white spaces) all the values of Column Name
I want to modify an existing gem to compatible with new rails versions. My
I want to modify the solution for highlighting trailing whitespace described here by NOT
I want to modify some code in the Eclipse JDT itself (In the Debug
I want to modify a connection string that's hard-coded in a Java application (jar
I want to modify my table view cell apparence when the delete button came
I want to modify the registry of window OS using c. kindly guide me

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.