首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部署后的Bugs

部署后的Bugs
EN

Stack Overflow用户
提问于 2013-08-03 02:34:45
回答 1查看 78关注 0票数 0

如果您查看这里的项目:http://www.leapfm.com/,您可以向下滚动并单击首页上的更多内容,它就可以工作了。但是,如果您尝试在“新建歌曲”选项卡中这样做,它将停留在“页面正在加载.”处。我不太清楚这是为什么。

new_songs.html.erb

代码语言:javascript
复制
<div id="new_songs">
<%= render 'new_songs'%>
</div></div>

_new_songs.html.erb (部分)

代码语言:javascript
复制
<div id="layout-1">
<!--div class="left-side"> -->
<%#= will_paginate @songs %>
<h6>New songs</h6>
<hr>
<ol><% @songs.each do |song| %>
<span class="title">
<li><%= link_to song.title, song %><span class="subtext">  (<%= song.url %>)<br></li></span>


 <%#=link_to '&#9660'.html_safe, vote_against_song_path(song), :remote => true, :method => :put %> 

    posted <%= time_ago_in_words(song.created_at) + " ago" %>
    <small><span class="comments"></small> | <%= pluralize(song.comments.size, 'comment') %></span></small><br /></span>

<%#= link_to 'Show', song, class: "button small secondary" %>
<%= link_to('Edit', edit_song_path(song), class: "button small secondary") if can? :update, song %>
<%= link_to('Destroy', song, method: :delete, data: {confirm: 'Are you sure?'}, class: "button small secondary") if can? :destroy, song %>

<% end %>

</ol>
</div>
<div class="pagination-centered">
  <ul class="pagination">
<%#= will_paginate @songs %>
<!-- or custom pagination -->
<% if @songs.previous_page %>
  <%= link_to "Back", params.merge(page: @songs.previous_page) %>
<% end %>
<% if @songs.next_page %>
  <%= link_to "More", params.merge(page: @songs.next_page) %>
<% end %>
</ul></div>

pagination.js

代码语言:javascript
复制
$(function() {
  $(".pagination a").on("click", function() {
    $(".pagination").html("Page is loading...");
    $.getScript(this.href);
    return false;
  });
});

song_controller.rb

代码语言:javascript
复制
class SongsController < ApplicationController
  before_filter :authenticate_user!, only: [:create ,:edit, :update, :destroy, :vote_for_song]
  before_action :set_song, only: [:show, :edit, :update, :destroy, :vote_for_song]

  def extract_video

  @song = Song.find(params[:id])
  @song.YouTubeAddy.extract_video_id

  end

  def vote_for
      @song = Song.find(params[:id])
      current_user.vote_for(@song)
      @song.plusminus = @song.votes_for
      @song.save
      respond_to do |format|
        format.js { render 'update_votes' }
      end
  end

  def vote_against
    @song = Song.find(params[:id])
    current_user.vote_against(@song)
    respond_to do |format|
      format.js { render 'update_votes' }
    end
  end

  def new_songs
    @songs = Song.order("id DESC").paginate(:page => params[:page], :per_page => 15)
  end


  # GET /Songs
  # GET /Songs.json
  def index
    if params[:genre]
      @songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
    else      
      @songs = Song.order('plusminus').paginate(:page => params[:page], :per_page => 15)
    end
  end

  # GET /Songs/1
  # GET /Songs/1.json
  def show
   @comment = Comment.new(song: @song) 
   @video_tag = YouTubeAddy.extract_video_id(@song.url)

  end

  # GET /Songs/new
  def new
    @song = Song.new
  end

  # GET /Songs/1/edit
  def edit
  end

  # POST /Songs
  # POST /Songs.json
  def create
    @song = Song.new(song_params)

    respond_to do |format|
      if @song.save
        format.html { redirect_to @song, notice: 'Song was successfully created.' }
        format.json { render action: 'show', status: :created, location: @song }
      else
        format.html { render action: 'new' }
        format.json { render json: @song.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /Songs/1
  # PATCH/PUT /Songs/1.json
  def update
    respond_to do |format|
      if @song.update(song_params)
        format.html { redirect_to @song, notice: 'Song was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @song.errors, status: :unprocessable_entity }
      end
    end
  end

  # Song /Songs/1
  # Song /Songs/1.json
  def destroy
    @song.destroy
    respond_to do |format|
      format.html { redirect_to songs_url }
      format.json { head :no_content }
    end
  end

  private

    def set_song
       @song = Song.find(params[:id])
     end

     def song_params
       params.require(:song).permit(:title, :artist, :url, :track, :user_id, :tag_list)
     end
  end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-04 00:32:40

您将两个操作的js代码放在同一个文件中。

index操作和new_songs操作在songs_controller.rb中,js放在index.js.erb中。

代码语言:javascript
复制
$("#songs").html("<%= escape_javascript(render("songs")) %>"); 
$("#new_songs").html("<%= escape_javascript(render("new_songs")) %>");

在一个名为new_songs.js.erb的文件中移动第二行,您就完成了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18028703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档