开发者

uninitialized constant with rails friendships

I'm new to rails and getting the following error:

NameError in FriendshipsController#create  
uninitialized constant FriendshipsController

this also shows up:

{"authenticity_token"=>"eQvv3flATE+P1TEErOWP/6fM8dEOIBxltobCxtM/F18=",
 "friend_id"=>"32"}

When I click on the "Add Friend" Link on my users show page. I am following the railscast about self referential associations to a T, but I keep getting this error and I can't find any information about it, not even what "uninitialized constant" means. I've gathered from the internet that it MAY be related to the acts_as_authenticated plugin, but I followed the one fix I found and it didn't work.

Here is the code from my user/show.html.erb page:

<%= link_to "Add Friend", friendships_path(:friend_id => @user.id), :method => :post %> 

and the code from my friendships controller:

def create
  @friendsh开发者_StackOverflow社区ip = current_user.friendships.build(:friend_id => params[:friend_id])
  if @friendship.save
    flash[:notice] = "Added friend."
    redirect_to root_url
  else
    flash[:error] = "Unable to add friend."
    redirect_to root_url
  end
end

Where am I going wrong here. I haven't the faintest clue what is causing this. Please let me know if I am missing any needed code.


Difficult to tell. You should post the top part of your class... requires, class definition, includes, and anything else you have that is outside of your methods, as well as the create method.


Rails is complaining because you have used a constant before initializing it.

puts SomeConstant
# before
SomeConstant = 10

In this case the constant is a controller Class Name - FriendshipsController

Check if the class name is correct, i.e. you have a controller with that name in your app\controller directory.


I think you run rails g controller Friendship

while you should have used rails g controller Friendships

thats why all files are now singular You can still go through and change all files though

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜