Note that there are some explanatory texts on larger screens.

plurals
  1. POMissing Template and Controller Issues in Rails Project (rating)
    text
    copied!<p>I am stuck on a problem and i would love a hand! I got the polymorphic association from railscast #154 </p> <p>So far I have gotten the comment model working splendidly. However I want to create a rating model as well that I can then add js to make pretty. </p> <p>Looked at every other tutorial/stackoverflows I could find. None of them show how to work with multiple polymorphic associations in a controller. </p> <p>I tried to duplicate the code for the article_controller but I am not sure how to do that for both models. So far my attempts have been unsuccessful. The partial form has the proper name, it is _ratings.html.erb</p> <p><strong>My Error:</strong></p> <pre><code>Missing partial ratings/ratings with {:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :coffee]}. Searched in: * "/code/jimbo/bigdog/app/views" * "/home/user/.rvm/gems/ruby-2.0.0-p247@lulla-core/gems/kaminari-0.14.1/app/views" * "/home/user/.rvm/gems/ruby-2.0.0-p247@lulla-core/gems/devise-3.1.1/app/views" </code></pre> <p><strong>My Models:</strong></p> <pre><code> class Rating include Mongoid::Document include Mongoid::MultiParameterAttributes field :value, type: Integer, default: "0" belongs_to :rateable, polymorphic: true end </code></pre> <p><strong>My Controllers:</strong></p> <pre><code>class RatingsController &lt; ApplicationController before_filter :load_rateable def index @ratings = @rateable.rating end def show @rating = @rateable.ratings.find(params[:id]) respond_to do |format| format.html # show.html.erb end end def new @rating = @rateable.rating.new end def create @rating = @rateable.rating.new(params[:rating]) if @rating.save redirect_to @rateable, notice: "Rating created." else render :new end end private def load_rateable resource, id = request.path.split('/')[1, 2] @rateable = resource.singularize.classify.constantize.find(id) end # def load_commentable # klass = [Article, Photo, Event].detect { |c| params["#{c.name.underscore}_id"] } # @rateable = klass.find(params["#{klass.name.underscore}_id"]) # end end </code></pre> <p><strong>Article Controller</strong></p> <pre><code>class ArticlesController &lt; ApplicationController # GET /articles # GET /articles.json def index @articles = Article.all respond_to do |format| format.html # index.html.erb format.json { render json: @articles } end end # GET /articles/1 # GET /articles/1.json def show @article = Article.find(params[:id]) @commentable = @article @comments = @commentable.comments @comment = Comment.new respond_to do |format| format.html # show.html.erb format.json { render json: @article } end end # GET /articles/new # GET /articles/new.json def new @article = Article.new respond_to do |format| format.html # new.html.erb format.json { render json: @article } end end # GET /articles/1/edit def edit @article = Article.find(params[:id]) end # POST /articles # POST /articles.json def create @article = Article.new(params[:article]) respond_to do |format| if @article.save format.html { redirect_to @article, notice: 'Article was successfully created.' } format.json { render json: @article, status: :created, location: @article } else format.html { render action: "new" } format.json { render json: @article.errors, status: :unprocessable_entity } end end end # PUT /articles/1 # PUT /articles/1.json def update @article = Article.find(params[:id]) respond_to do |format| if @article.update_attributes(params[:article]) format.html { redirect_to @article, notice: 'Article was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @article.errors, status: :unprocessable_entity } end end end # DELETE /articles/1 # DELETE /articles/1.json def destroy @article = Article.find(params[:id]) @article.destroy respond_to do |format| format.html { redirect_to articles_url } format.json { head :no_content } end end end </code></pre> <p><strong>My View:</strong> </p> <p>show.html (article)</p> <pre><code>&lt;%= render "comments/comments" %&gt; &lt;%= render "comments/form" %&gt; &lt;%= render "ratings/ratings" %&gt; &lt;%= render "ratings/form" %&gt; </code></pre> <p><strong>Routes:</strong></p> <pre><code> resources :articles do resources :comments resources :ratings end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload