I have changed the code like this
class BranchesController < ApplicationController
def branch @branch = Branch.new
end
def create @branch = Branch.new(params[:branch])
end
end
branch.html.erb in branches folder
<%= form_for(@branch) do |f| %>
<%end%>
Now the problem is if i want to display some value from branches
controller
to branch.html.erb, i have to define that in branch method
in BranchesController, but here all the functionality can be done in
create method in BranchesController, so that way i didn’t get any values
in
branch.html.erb, How to do that…?. How to write that in branch
method?.. if the branch method not in BranchesController, the error will
be undefined method model_name nill class, also if the create method not
in BranchesController, the error will be the action create not found
branch.html.erb in branches folder
if the branch method not inBranchesController, the error will be undefined
method model_name nill class, also if the create method not
inBranchesController, the error will be the action create not found
What am i doing wrong
I don’t have much idea about what problem you are trying to describe,
I presume English is not your first language and understand it can be
difficult to explain a problem clearly. If I am right then you have
an action branch in the branches controller but have the problem that
in order for data to be seen in the view then you have to setup
variables in that action. If you don’t want to set them up there then
possibly a before_filter is what you want.
If I am not understanding the problem correctly then please try again
to explain it. Cut your example down to the absolute minimum code
required and show what you are trying to do and what the problem is.
After writing your description of the problem imagine yourself as
someone who knows nothing about your requirement, read your
description carefully, and make sure the description of the problem is
clear.
if i have to get @name in branch.html.erb, i have to define that branch
action in BranchesController, am i correct…?. So in this application all
the main function done in create action in BranchesController. In that way
how to get that values in branch.html.erb
Use before_filter to setup @name for both create and branch.
On Saturday, 21 April 2012 03:56:02 UTC-4, Colin L. wrote:
end
in BranchesController, but here all the functionality can be done in
I don’t have much idea about what problem you are trying to describe,
I presume English is not your first language and understand it can be
difficult to explain a problem clearly. If I am right then you have
an action branch in the branches controller but have the problem that
in order for data to be seen in the view then you have to setup
variables in that action. If you don’t want to set them up there then
possibly a before_filter is what you want.
Thanks colin,
what i am trying to do,
branches_controller
*
*
class BranchesController < ApplicationController
def branch @branch = Branch.new
end
def create @branch = Branch.new(params[:branch]) @name = “vishnu”
end
end
branch.html.erb
new <%=@name %>
<%= form_for(@branch) do |f| %>
<%= f.submit "Save" %>
<%end%>
if i have to get @name in branch.html.erb, i have to define that branch
action in BranchesController, am i correct…?. So in this application
all
the main function done in create action in BranchesController. In that
way
how to get that values in branch.html.erb
class BranchesController < ApplicationController
branch.html.erb
how to get that values in branch.html.erb
def create @branch = Branch.new(params[:branch]) @name = “vishnu”
end
end
Is it correct way…?
No, have a look at the Rails Guide on Action Controller Overview to
see how to use it. Also google for
rails before_filter
to find many examples and documentation.
On Saturday, 21 April 2012 04:19:05 UTC-4, Colin L. wrote:
end
<%= f.submit “Save” %>
<%end%>
if i have to get @name in branch.html.erb, i have to define that branch
action in BranchesController, am i correct…?. So in this application
all
the main function done in create action in BranchesController. In that
way
how to get that values in branch.html.erb
Thanks
Can i do like that,
class BranchesController < ApplicationController
before_filter :branch,:create
def branch
@branch = Branch.new
end
def create
@branch = Branch.new(params[:branch])
@name = "vishnu"
end
On Saturday, 21 April 2012 04:44:57 UTC-4, Colin L. wrote:
branches_controller
end
all
def branch
No, have a look at the Rails Guide on Action Controller Overview to
see how to use it. Also google for
rails before_filter
to find many examples and documentation.
but i didn’t get that correctly, when i use the access
specifier(private,protected),i am trying that for 2 days, i have got the
issues…can u rearrange with the above code, for accessing
instancevariablein all action…
but i didn’t get that correctly, when i use the access
specifier(private,protected),i am trying that for 2 days, i have got the
issues…can u rearrange with the above code, for accessing
instancevariablein all action…
Show us what you tried and what happened.
Just use a simple before_filter initially to get it working.
On Sunday, 22 April 2012 07:10:02 UTC-4, Colin L. wrote:
end
end
Thanks colin, thank you
when i compare this code with my application code, in the above code,
before doing all the method, the setup method will run, and set the
variables, so that can be accessed for all methods. But here i have one
doubt, This is my application structure…
end
My doubt is if i display any variable(example is @name = vishnu) in
page.html.erb, i have to create one page action in PagesController…?
or
any other way to access…?
but i didn’t get that correctly, when i use the access
before_filter :create @name = “vishnu”
end
end
Here the create is my calling function,i mean when i click the button that
create function will call, ie Branches#create.
Don’t try and call one of the actions in the filter. Add a new method
that is called from the before filter and sets up what you want, so
possibly
before_filter :setup
and
private
def setup @name = “vishnu”
end
Then setup will be called before each action.
By putting it in the private section of the controller the setup
method is not available as an action itself, but just as a method that
can be called within the controller
end
My doubt is if i display any variable(example is @name = vishnu) in
page.html.erb, i have to create one page action in PagesController…? or
any other way to access…?
Sorry, no idea what you mean.
Colin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.