Kevin
Kevin

Reputation: 1614

Rails help with devise

Hey I was trying to make an association in devise so a user can just have a link to his association (like he can just click new post and he can make it) but i cant make it in devise like regular rails, it seems really common but no one seems able to help me (or they dont know what im talking about), I tried manually making come controllers and views but i get a problem (500 internal server error) heres my log file https://github.com/Kevin-Mohamed/mygit any other information needed let me know

Upvotes: 0

Views: 98

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

OK, so this is off the top of my head, so YMMV. There's plenty of ways to go around this, but here's one way... Don't try to get devise to do more than it should.

class User
  #devise links go here
  has_many :pictures
end

class Picture
  belongs_to :user
end

#routes
namespace :my do
  resources :pictures
end

class ApplicationController
  # current_user gets set here by devise
end

class PicturesController
  def create
    @picture = current_user.pictures.build(params[:picture])
  end
end

#In your view you'd have the following, which would post to /my/pictures

=form_for(my_pictures_path(@picture)) do |f|
  ... etc

Upvotes: 1

Related Questions