开发者

Rails routes and model woes

I'm a little new to rails sorry if this seems basic

Alright so here's the deal I'm creating an application that will have many users and all the users have many songs. However when I try to create a song I get the following error:No action responded to 1. Actions: create and new and my browser is at the url: http://0.0.0.0:3000/users/1/songs which is not the correct route it should have redirected to songs/create

Here is my controller code:

class SongsController < ApplicationController

  def index
    @user = current_user
    @songs = @user.songs
  end

  def new 
 @user = current_user
 @song = @user.songs.build
  end

  def create
 @user = current_user
 @song = @user.songs.build(params[:song])
 if @song.save
  redirect_to user_song_url(@user, @song)
 else
  render :action => "new"
 end
  end

end

If anyone can h开发者_如何学编程elp I would greatly appreciate it.


The create method is reserved for POST /users URL if you use map.resources :users.

If you want change that, you need define all your route manually or with default route.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜