Answer the question
In order to leave comments, you need to log in
What is the correct way to use helpers in Ruby on Rails?
Good afternoon! I apologize in advance if I make a mistake in the terminology: a beginner in RoR, I study the language by typing and intensively studying search queries, but I could not get a clear answer to this question, unfortunately.
There are two tables Journals (a list of journals) and Publications (a list of issues for each journal), the relationship is one to many. I created the corresponding objects in RoR, there were no problems at all for journals - I managed to create a view for creating, editing, viewing, displaying a list. Now I'm approaching the creation of similar views for publications, and a couple of times I came across the following problem with using helpers in .html.erb.
I want to show the "Go to the list of all journal publications" button when showing the journal (show.html.erb for journals). As I understand it, you need to write a link_to of the following form:
<%= link_to 'К списку публикаций журнала', journal_publications_path (@journal) %>
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
persons_profile GET /persons/profile(.:format) persons#profile
article_comments GET /articles/:article_id/comments(.:format) comments#index
POST /articles/:article_id/comments(.:format) comments#create
new_article_comment GET /articles/:article_id/comments/new(.:format) comments#new
edit_article_comment GET /articles/:article_id/comments/:id/edit(.:format) comments#edit
article_comment GET /articles/:article_id/comments/:id(.:format) comments#show
PATCH /articles/:article_id/comments/:id(.:format) comments#update
PUT /articles/:article_id/comments/:id(.:format) comments#update
DELETE /articles/:article_id/comments/:id(.:format) comments#destroy
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
journal_publications GET /journals/:journal_id/publications(.:format) publications#index
POST /journals/:journal_id/publications(.:format) publications#create
new_journal_publication GET /journals/:journal_id/publications/new(.:format) publications#new
edit_journal_publication GET /journals/:journal_id/publications/:id/edit(.:format) publications#edit
journal_publication GET /journals/:journal_id/publications/:id(.:format) publications#show
PATCH /journals/:journal_id/publications/:id(.:format) publications#update
PUT /journals/:journal_id/publications/:id(.:format) publications#update
DELETE /journals/:journal_id/publications/:id(.:format) publications#destroy
journals GET /journals(.:format) journals#index
POST /journals(.:format) journals#create
new_journal GET /journals/new(.:format) journals#new
edit_journal GET /journals/:id/edit(.:format) journals#edit
journal GET /journals/:id(.:format) journals#show
PATCH /journals/:id(.:format) journals#update
PUT /journals/:id(.:format) journals#update
DELETE /journals/:id(.:format) journals#destroy
articles_index GET /articles/index(.:format) articles#index
root GET / articles#index
SyntaxError in JournalsController#show
/home/rubyuser/ruby/blog/app/views/journals/show.html.erb:14: syntax error, unexpected ( arg, expecting keyword_do or '{' or '(' ...а', journal_publications_path (journal_id), :class => 'journ... ... ^ /home/rubyuser/ruby/blog/app/views/journals/show.html.erb:14: syntax error, unexpected ',', expecting ')' ...publications_path (journal_id), :class => 'journalslist-gray... ... ^
Answer the question
In order to leave comments, you need to log in
You have an extra space before the parenthesis. Must be
<%= link_to 'К списку публикаций журнала', journal_publications_path(@journal) %>
About how, I'm used to Delphi, in which you can put as many spaces as you like between the name of the procedure and the variables being transferred. Thank you very much for your help, I'll keep it in mind.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question