Rails 帮助设计

发布于 2024-12-07 09:48:06 字数 274 浏览 1 评论 0原文

嘿,我试图在设计中建立一个关联,这样用户就可以有一个指向他的关联的链接(就像他只需单击新帖子,他就可以做到),但我不能像常规轨道那样在设计中建立它,这似乎很常见但似乎没有人能够帮助我(或者他们不知道我在说什么),我尝试手动制作控制器和视图,但我遇到了问题(500内部服务器错误)这是我的日志文件 https://github.com/Kevin-Mohamed/mygit 需要任何其他信息请告诉我

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2024-12-14 09:48:06

好吧,这就是我的想法,所以 YMMV。有很多方法可以解决这个问题,但这里有一种方法……不要试图让设计做超出应有的事情。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文