Rails 4 using strong parameters without controller

Rails 4: I am coming out of rails 3.2.x And I have a question. How to use Strong parameter without controller.

I have this model:

Track (the only one that has a Controller  )
  has_many :tracksegments, :dependent => :destroy
  has_many :points, :through => :tracksegments
Tracksegment
  belongs_to :track
  has_many :points, :dependent => :destroy
points
  belongs_to :tracksegment

The track is the only one that has a controller, so it has some powerful parameters.

I want to know where I can put the parameters belonging to "tracksegment" and "points". In Rails 3.x it is hidden in the model, but in rails 4 I do not have a controller for them.

+4
source share
3 answers

You enable parameters in which controller you send them. It looks like you are sending them through your track controller, if so you added them.

. , Rails 4 - -

+3

, " " :

, , , .

, JSON API- Model.create, . , - ActionController:: Parameters , . :

raw_parameters = { :email => "john@example.com", :name => "John", :admin => true }
parameters = ActionController::Parameters.new(raw_parameters)
user = User.create(parameters.permit(:name, :email))

https://github.com/rails/strong_parameters

+6

. Rails 4, , attr_accessible.

, , -

def create 
@track = Track.create(track_params)
end

private

def track_params
params.require(:track).permit(:param1, :param2, :param2)
end

, , .

+1

Source: https://habr.com/ru/post/1524762/


All Articles