提交后表单输入不保存

时间:2013-08-01 01:20:20

标签: ruby-on-rails ruby-on-rails-4

所以,我今天让朋友在我的应用程序上工作,现在:表单的url,'website url'部分没有保存,但剩下的就是。不知道为什么会这样。我进入控制台并不得不手动设置它以便在浏览器中显示。

<div class="row">
    <div class="large-6 columns">
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>

<div class="field"> 
<%= f.label 'website url' %> 
<%= f.text_area :url %> <----------- this field isn't saving anymore.
</div>
<div class="field">
  <%= f.label :tag_list, "Genres (separated by commas)" %><br />
  <%= f.text_field :tag_list %>
</div>
<p>
<%= f.file_field :track%>
</p>

<div class="actions">
    <%= f.submit value: "Upload" %>
</div>

架构snippit

 create_table "songs", force: true do |t|
    t.string   "title"
    t.string   "artist"
    t.text     "url"
    t.string   "track_file_name"
    t.string   "track_content_type"
    t.integer  "track_file_size"
    t.datetime "track_updated_at"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "plusminus"
  end

song_controller.rb

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 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"
  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) 
  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, :bio, :track, :user_id, :tag_list)
     end
  end

1 个答案:

答案 0 :(得分:1)

在params.require(:song).permit列表中添加:url是否可以解决问题?