Created
February 27, 2009 10:48
-
-
Save Baael/71409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# teraz uzyjemy form_for bo mamy obiekt | |
<div><%= error_messages_for 'news' %></div> | |
<% form_for(@news, :url => {:controller =>'news', :action =>'create'}) do |f| %> | |
Temat:<%= f.text_field :subject %><br /> | |
Skrót:<%= f.text_field :body_short %><br /> | |
News:<%= f.text_field :body %><br /> | |
Data publikacji:<%= f.text_field :public_date%><br /> | |
## wyjeb ta linijke ! | |
##Publikowany przez:<%= f.text_field :user, session[:login] %><br /> | |
<%= f.submit('dadaj newsa', :confirm => 'chcesz je dodać?') %> | |
<% end %> | |
<%= link_to 'wróć', :controller => 'admin' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#rozwijasz teraz metode create: | |
def create | |
#RELACJA Z USEREM | |
user=User.find_by_login(session[:login]) || User.first | |
#tworzysz newsa w oparciu o strukture jaką dostałeś z parametrów formularza | |
@news=user.news.new params[:news] | |
#sprawdzasz czy sie zapisuje (czyli czy przechodzi walidacje) | |
if @news.save | |
#jesli tak to zajebiscie i przekierowujemy sie do listy | |
redirect_to :action => :index | |
else | |
#jesli nie to przejebane i musimy jeszcze raz go wypelnic | |
#czyli wyswietlamy (ale nie przekierowywujemy!) formularz | |
render :action => :new | |
#renderujemy szablon akcji "new" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment